| 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 deprecatedFutureValue(_FutureImpl future) => | 7 deprecatedFutureValue(_FutureImpl future) => |
| 8 future._isComplete ? future._resultOrListeners : null; | 8 future._isComplete ? future._resultOrListeners : null; |
| 9 | 9 |
| 10 | 10 |
| 11 class _CompleterImpl<T> implements Completer<T> { | 11 class _CompleterImpl<T> implements Completer<T> { |
| 12 final Future<T> future; | 12 final Future<T> future; |
| 13 bool _isComplete = false; | 13 bool _isComplete = false; |
| 14 | 14 |
| 15 _CompleterImpl() : future = new _FutureImpl<T>(); | 15 _CompleterImpl() : future = new _FutureImpl<T>(); |
| 16 | 16 |
| 17 void complete(T value) { | 17 void complete([T value]) { |
| 18 if (_isComplete) throw new StateError("Future already completed"); | 18 if (_isComplete) throw new StateError("Future already completed"); |
| 19 _isComplete = true; | 19 _isComplete = true; |
| 20 _FutureImpl future = this.future; | 20 _FutureImpl future = this.future; |
| 21 future._setValue(value); | 21 future._setValue(value); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void completeError(Object error, [Object stackTrace = null]) { | 24 void completeError(Object error, [Object stackTrace = null]) { |
| 25 if (_isComplete) throw new StateError("Future already completed"); | 25 if (_isComplete) throw new StateError("Future already completed"); |
| 26 _isComplete = true; | 26 _isComplete = true; |
| 27 new Timer(0, (_) { | 27 new Timer(0, (_) { |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 Future catchError(function(AsyncError error), {bool test(var error)}) { | 451 Future catchError(function(AsyncError error), {bool test(var error)}) { |
| 452 return _future.catchError(function, test: test); | 452 return _future.catchError(function, test: test); |
| 453 } | 453 } |
| 454 | 454 |
| 455 Future whenComplete(void action()) { | 455 Future whenComplete(void action()) { |
| 456 return _future.whenComplete(action); | 456 return _future.whenComplete(action); |
| 457 } | 457 } |
| 458 | 458 |
| 459 Stream<T> asStream() => new Stream.fromFuture(this); | 459 Stream<T> asStream() => new Stream.fromFuture(this); |
| 460 } | 460 } |
| OLD | NEW |