| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 import 'package:async/async.dart'; | 8 import 'package:async/async.dart'; |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 Future/*<T>*/ withResource/*<T>*/(/*=T*/ callback()) { | 109 Future/*<T>*/ withResource/*<T>*/(/*=T*/ callback()) { |
| 110 if (isClosed) { | 110 if (isClosed) { |
| 111 throw new StateError( | 111 throw new StateError( |
| 112 "withResource() may not be called on a closed Pool."); | 112 "withResource() may not be called on a closed Pool."); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // We can't use async/await here because we need to start the request | 115 // We can't use async/await here because we need to start the request |
| 116 // synchronously in case the pool is closed immediately afterwards. Async | 116 // synchronously in case the pool is closed immediately afterwards. Async |
| 117 // functions have an asynchronous gap between calling and running the body, | 117 // functions have an asynchronous gap between calling and running the body, |
| 118 // and [close] could be called during that gap. See #3. | 118 // and [close] could be called during that gap. See #3. |
| 119 return request().then((resource) { | 119 return request().then/*<Future<T>>*/((resource) { |
| 120 return new Future.sync(callback).whenComplete(resource.release); | 120 return new Future/*<T>*/.sync(callback).whenComplete(resource.release); |
| 121 }); | 121 }); |
| 122 } | 122 } |
| 123 | 123 |
| 124 /// Closes the pool so that no more resources are requested. | 124 /// Closes the pool so that no more resources are requested. |
| 125 /// | 125 /// |
| 126 /// Existing resource requests remain unchanged. | 126 /// Existing resource requests remain unchanged. |
| 127 /// | 127 /// |
| 128 /// Any resources that are marked as releasable using | 128 /// Any resources that are marked as releasable using |
| 129 /// [PoolResource.allowRelease] are released immediately. Once all resources | 129 /// [PoolResource.allowRelease] are released immediately. Once all resources |
| 130 /// have been released and any `onRelease` callbacks have completed, the | 130 /// have been released and any `onRelease` callbacks have completed, the |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 /// produce additional information later on. For example, an isolate's task | 258 /// produce additional information later on. For example, an isolate's task |
| 259 /// may be complete, but it could still emit asynchronous errors. | 259 /// may be complete, but it could still emit asynchronous errors. |
| 260 void allowRelease(onRelease()) { | 260 void allowRelease(onRelease()) { |
| 261 if (_released) { | 261 if (_released) { |
| 262 throw new StateError("A PoolResource may only be released once."); | 262 throw new StateError("A PoolResource may only be released once."); |
| 263 } | 263 } |
| 264 _released = true; | 264 _released = true; |
| 265 _pool._onResourceReleaseAllowed(onRelease); | 265 _pool._onResourceReleaseAllowed(onRelease); |
| 266 } | 266 } |
| 267 } | 267 } |
| OLD | NEW |