| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.pool; | 5 library barback.pool; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
| 11 | 11 |
| 12 // TODO(nweiz): put this somewhere that it can be shared between packages. |
| 12 /// Manages an abstract pool of resources with a limit on how many may be in use | 13 /// Manages an abstract pool of resources with a limit on how many may be in use |
| 13 /// at once. | 14 /// at once. |
| 14 /// | 15 /// |
| 15 /// When a resource is needed, the user should call [request]. When the returned | 16 /// When a resource is needed, the user should call [request]. When the returned |
| 16 /// future completes with a [PoolResource], the resource may be allocated. Once | 17 /// future completes with a [PoolResource], the resource may be allocated. Once |
| 17 /// the resource has been released, the user should call [PoolResource.release]. | 18 /// the resource has been released, the user should call [PoolResource.release]. |
| 18 /// The pool will ensure that only a certain number of [PoolResource]s may be | 19 /// The pool will ensure that only a certain number of [PoolResource]s may be |
| 19 /// allocated at once. | 20 /// allocated at once. |
| 20 class Pool { | 21 class Pool { |
| 21 /// Completers for requests beyond the first [_maxAllocatedResources]. | 22 /// Completers for requests beyond the first [_maxAllocatedResources]. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 /// Tells the parent [Pool] that the resource associated with this resource is | 130 /// Tells the parent [Pool] that the resource associated with this resource is |
| 130 /// no longer allocated, and that a new [PoolResource] may be allocated. | 131 /// no longer allocated, and that a new [PoolResource] may be allocated. |
| 131 void release() { | 132 void release() { |
| 132 if (_released) { | 133 if (_released) { |
| 133 throw new StateError("A PoolResource may only be released once."); | 134 throw new StateError("A PoolResource may only be released once."); |
| 134 } | 135 } |
| 135 _released = true; | 136 _released = true; |
| 136 _pool._onResourceReleased(); | 137 _pool._onResourceReleased(); |
| 137 } | 138 } |
| 138 } | 139 } |
| OLD | NEW |