OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.async; | 5 part of dart.async; |
6 | 6 |
7 /** The onValue and onError handlers return either a value or a future */ | 7 /** The onValue and onError handlers return either a value or a future */ |
8 typedef dynamic _FutureOnValue<T>(T value); | 8 typedef dynamic _FutureOnValue<T>(T value); |
9 /** Test used by [Future.catchError] to handle skip some errors. */ | 9 /** Test used by [Future.catchError] to handle skip some errors. */ |
10 typedef bool _FutureErrorTest(var error); | 10 typedef bool _FutureErrorTest(var error); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 226 |
227 Future<T> whenComplete(action()) { | 227 Future<T> whenComplete(action()) { |
228 _Future result = new _Future<T>(); | 228 _Future result = new _Future<T>(); |
229 if (!identical(result._zone, _ROOT_ZONE)) { | 229 if (!identical(result._zone, _ROOT_ZONE)) { |
230 action = result._zone.registerCallback(action); | 230 action = result._zone.registerCallback(action); |
231 } | 231 } |
232 _addListener(new _FutureListener.whenComplete(result, action)); | 232 _addListener(new _FutureListener.whenComplete(result, action)); |
233 return result; | 233 return result; |
234 } | 234 } |
235 | 235 |
236 Stream<T> asStream() => new Stream.fromFuture(this); | 236 Stream<T> asStream() => new Stream<T>.fromFuture(this); |
237 | 237 |
238 void _markPendingCompletion() { | 238 void _markPendingCompletion() { |
239 if (!_mayComplete) throw new StateError("Future already completed"); | 239 if (!_mayComplete) throw new StateError("Future already completed"); |
240 _state = _PENDING_COMPLETE; | 240 _state = _PENDING_COMPLETE; |
241 } | 241 } |
242 | 242 |
243 T get _value { | 243 T get _value { |
244 assert(_isComplete && _hasValue); | 244 assert(_isComplete && _hasValue); |
245 return _resultOrListeners; | 245 return _resultOrListeners; |
246 } | 246 } |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 } | 652 } |
653 }, onError: (e, s) { | 653 }, onError: (e, s) { |
654 if (timer.isActive) { | 654 if (timer.isActive) { |
655 timer.cancel(); | 655 timer.cancel(); |
656 result._completeError(e, s); | 656 result._completeError(e, s); |
657 } | 657 } |
658 }); | 658 }); |
659 return result; | 659 return result; |
660 } | 660 } |
661 } | 661 } |
OLD | NEW |