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; | 5 library async.cancelable_operation; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:async/async.dart'; | 9 import 'package:async/async.dart'; |
10 | 10 |
11 /// An asynchronuos operation that can be cancelled. | 11 /// An asynchronous operation that can be cancelled. |
12 /// | 12 /// |
13 /// The value of this operation is exposed as [value]. When this operation is | 13 /// 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 | 14 /// cancelled, [value] won't complete either successfully or with an error. If |
15 /// [value] has already completed, cancelling the operation does nothing. | 15 /// [value] has already completed, cancelling the operation does nothing. |
16 class CancelableOperation<T> { | 16 class CancelableOperation<T> { |
17 /// The completer that produced this operation. | 17 /// The completer that produced this operation. |
18 /// | 18 /// |
19 /// This is canceled when [cancel] is called. | 19 /// This is canceled when [cancel] is called. |
20 final CancelableCompleter<T> _completer; | 20 final CancelableCompleter<T> _completer; |
21 | 21 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 _inner.completeError(error, stackTrace); | 139 _inner.completeError(error, stackTrace); |
140 } | 140 } |
141 | 141 |
142 /// Cancel the completer. | 142 /// Cancel the completer. |
143 Future _cancel() => _cancelMemo.runOnce(() { | 143 Future _cancel() => _cancelMemo.runOnce(() { |
144 if (_inner.isCompleted) return null; | 144 if (_inner.isCompleted) return null; |
145 _isCanceled = true; | 145 _isCanceled = true; |
146 if (_onCancel != null) return _onCancel(); | 146 if (_onCancel != null) return _onCancel(); |
147 }); | 147 }); |
148 } | 148 } |
OLD | NEW |