| 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 library cancelable_future; | 5 library analyzer.src.cancelable_future; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Type of callback called when the future returned by a CancelableCompleter | 10 * Type of callback called when the future returned by a CancelableCompleter |
| 11 * is canceled. | 11 * is canceled. |
| 12 */ | 12 */ |
| 13 typedef void CancelHandler(); | 13 typedef void CancelHandler(); |
| 14 | 14 |
| 15 /** | 15 /** |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // StreamSubscription.cancel() cancels the future. | 241 // StreamSubscription.cancel() cancels the future. |
| 242 return _completer._outerCompleter.future.asStream(); | 242 return _completer._outerCompleter.future.asStream(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 @override | 245 @override |
| 246 void cancel() { | 246 void cancel() { |
| 247 _completer._cancel(); | 247 _completer._cancel(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 @override | 250 @override |
| 251 Future catchError(Function onError, {bool test(Object error)}) => | 251 Future<T> catchError(Function onError, {bool test(Object error)}) => |
| 252 _completer._outerCompleter.future.catchError(onError, test: test); | 252 _completer._outerCompleter.future.catchError(onError, test: test); |
| 253 | 253 |
| 254 @override | 254 @override |
| 255 Future then(onValue(T value), {Function onError}) => | 255 Future/*<S>*/ then/*<S>*/(onValue(T value), {Function onError}) => |
| 256 _completer._outerCompleter.future.then(onValue, onError: onError); | 256 _completer._outerCompleter.future.then(onValue, onError: onError); |
| 257 | 257 |
| 258 @override | 258 @override |
| 259 Future timeout(Duration timeLimit, {onTimeout()}) { | 259 Future<T> timeout(Duration timeLimit, {onTimeout()}) { |
| 260 // TODO(paulberry): Implement this in such a way that a timeout cancels | 260 // TODO(paulberry): Implement this in such a way that a timeout cancels |
| 261 // the future. | 261 // the future. |
| 262 return _completer._outerCompleter.future | 262 return _completer._outerCompleter.future |
| 263 .timeout(timeLimit, onTimeout: onTimeout); | 263 .timeout(timeLimit, onTimeout: onTimeout); |
| 264 } | 264 } |
| 265 | 265 |
| 266 @override | 266 @override |
| 267 Future<T> whenComplete(action()) => | 267 Future<T> whenComplete(action()) => |
| 268 _completer._outerCompleter.future.whenComplete(action); | 268 _completer._outerCompleter.future.whenComplete(action); |
| 269 } | 269 } |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * A CancelableFuture that wraps an ordinary Future. Attempting to cancel a | 272 * A CancelableFuture that wraps an ordinary Future. Attempting to cancel a |
| 273 * _WrappedFuture has no effect. | 273 * _WrappedFuture has no effect. |
| 274 */ | 274 */ |
| 275 class _WrappedFuture<T> implements CancelableFuture<T> { | 275 class _WrappedFuture<T> implements CancelableFuture<T> { |
| 276 final Future<T> _future; | 276 final Future<T> _future; |
| 277 | 277 |
| 278 _WrappedFuture(this._future); | 278 _WrappedFuture(this._future); |
| 279 | 279 |
| 280 @override | 280 @override |
| 281 Stream<T> asStream() => _future.asStream(); | 281 Stream<T> asStream() => _future.asStream(); |
| 282 | 282 |
| 283 @override | 283 @override |
| 284 void cancel() {} | 284 void cancel() {} |
| 285 | 285 |
| 286 @override | 286 @override |
| 287 Future catchError(Function onError, {bool test(Object error)}) => | 287 Future<T> catchError(Function onError, {bool test(Object error)}) => |
| 288 _future.catchError(onError, test: test); | 288 _future.catchError(onError, test: test); |
| 289 | 289 |
| 290 @override | 290 @override |
| 291 Future then(onValue(value), {Function onError}) => | 291 Future/*<S>*/ then/*<S>*/(onValue(T value), {Function onError}) => |
| 292 _future.then(onValue, onError: onError); | 292 _future.then(onValue, onError: onError); |
| 293 | 293 |
| 294 @override | 294 @override |
| 295 Future timeout(Duration timeLimit, {onTimeout()}) => | 295 Future<T> timeout(Duration timeLimit, {onTimeout()}) => |
| 296 _future.timeout(timeLimit, onTimeout: onTimeout); | 296 _future.timeout(timeLimit, onTimeout: onTimeout); |
| 297 | 297 |
| 298 @override | 298 @override |
| 299 Future<T> whenComplete(action()) => _future.whenComplete(action); | 299 Future<T> whenComplete(action()) => _future.whenComplete(action); |
| 300 } | 300 } |
| OLD | NEW |