OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 async.cancelable_operation; | |
6 | |
7 import 'dart:async'; | 5 import 'dart:async'; |
8 | 6 |
9 import 'package:async/async.dart'; | 7 import 'package:async/async.dart'; |
10 | 8 |
11 /// An asynchronous operation that can be cancelled. | 9 /// An asynchronous operation that can be cancelled. |
12 /// | 10 /// |
13 /// The value of this operation is exposed as [value]. When this operation is | 11 /// The value of this operation is exposed as [value]. When this operation is |
14 /// cancelled, [value] won't complete either successfully or with an error. If | 12 /// cancelled, [value] won't complete either successfully or with an error. If |
15 /// [value] has already completed, cancelling the operation does nothing. | 13 /// [value] has already completed, cancelling the operation does nothing. |
16 class CancelableOperation<T> { | 14 class CancelableOperation<T> { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 /// Cancel the completer. | 158 /// Cancel the completer. |
161 Future _cancel() { | 159 Future _cancel() { |
162 if (_inner.isCompleted) return new Future.value(); | 160 if (_inner.isCompleted) return new Future.value(); |
163 | 161 |
164 return _cancelMemo.runOnce(() { | 162 return _cancelMemo.runOnce(() { |
165 _isCanceled = true; | 163 _isCanceled = true; |
166 if (_onCancel != null) return _onCancel(); | 164 if (_onCancel != null) return _onCancel(); |
167 }); | 165 }); |
168 } | 166 } |
169 } | 167 } |
OLD | NEW |