| OLD | NEW |
| 1 import 'dart:async'; | 1 import 'dart:async'; |
| 2 | 2 |
| 3 library barback.cancelable_future; |
| 4 |
| 3 /// A wrapper for [Future] that can be cancelled. | 5 /// A wrapper for [Future] that can be cancelled. |
| 4 /// | 6 /// |
| 5 /// When this is cancelled, that means it won't complete either successfully or | 7 /// When this is cancelled, that means it won't complete either successfully or |
| 6 /// with an error, regardless of whether the wrapped Future completes. | 8 /// with an error, regardless of whether the wrapped Future completes. |
| 7 /// Cancelling this won't stop whatever code is feeding the wrapped future from | 9 /// Cancelling this won't stop whatever code is feeding the wrapped future from |
| 8 /// running. | 10 /// running. |
| 9 class CancelableFuture<T> implements Future<T> { | 11 class CancelableFuture<T> implements Future<T> { |
| 10 bool _canceled = false; | 12 bool _canceled = false; |
| 11 final _completer = new Completer<T>(); | 13 final _completer = new Completer<T>(); |
| 12 | 14 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 25 _completer.future.catchError(onError, test: test); | 27 _completer.future.catchError(onError, test: test); |
| 26 Future then(onValue(T value), {onError(error)}) => | 28 Future then(onValue(T value), {onError(error)}) => |
| 27 _completer.future.then(onValue, onError: onError); | 29 _completer.future.then(onValue, onError: onError); |
| 28 Future<T> whenComplete(action()) => _completer.future.whenComplete(action); | 30 Future<T> whenComplete(action()) => _completer.future.whenComplete(action); |
| 29 | 31 |
| 30 /// Cancels this future. | 32 /// Cancels this future. |
| 31 void cancel() { | 33 void cancel() { |
| 32 _canceled = true; | 34 _canceled = true; |
| 33 } | 35 } |
| 34 } | 36 } |
| OLD | NEW |