| 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.result_future; | |
| 6 | |
| 7 import 'dart:async'; | 5 import 'dart:async'; |
| 8 | 6 |
| 7 import '../delegate/future.dart'; |
| 9 import '../result.dart'; | 8 import '../result.dart'; |
| 10 import 'delegate/future.dart'; | |
| 11 | 9 |
| 12 /// A [Future] wrapper that provides synchronous access to the result of the | 10 /// A [Future] wrapper that provides synchronous access to the result of the |
| 13 /// wrapped [Future] once it's completed. | 11 /// wrapped [Future] once it's completed. |
| 14 class ResultFuture<T> extends DelegatingFuture<T> { | 12 class ResultFuture<T> extends DelegatingFuture<T> { |
| 15 /// Whether the future has fired and [result] is available. | 13 /// Whether the future has fired and [result] is available. |
| 16 bool get isComplete => result != null; | 14 bool get isComplete => result != null; |
| 17 | 15 |
| 18 /// The result of the wrapped [Future], if it's completed. | 16 /// The result of the wrapped [Future], if it's completed. |
| 19 /// | 17 /// |
| 20 /// If it hasn't completed yet, this will be `null`. | 18 /// If it hasn't completed yet, this will be `null`. |
| 21 Result<T> get result => _result; | 19 Result<T> get result => _result; |
| 22 Result<T> _result; | 20 Result<T> _result; |
| 23 | 21 |
| 24 factory ResultFuture(Future<T> future) { | 22 factory ResultFuture(Future<T> future) { |
| 25 var resultFuture; | 23 var resultFuture; |
| 26 resultFuture = new ResultFuture._(Result.capture(future).then((result) { | 24 resultFuture = new ResultFuture._(Result.capture(future).then((result) { |
| 27 resultFuture._result = result; | 25 resultFuture._result = result; |
| 28 return result.asFuture; | 26 return result.asFuture; |
| 29 })); | 27 })); |
| 30 return resultFuture; | 28 return resultFuture; |
| 31 } | 29 } |
| 32 | 30 |
| 33 ResultFuture._(Future<T> future) | 31 ResultFuture._(Future<T> future) |
| 34 : super(future); | 32 : super(future); |
| 35 } | 33 } |
| OLD | NEW |