OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library async.result_future; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import '../result.dart'; | |
10 import 'delegate/future.dart'; | |
11 | |
12 /// A [Future] wrapper that provides synchronous access to the result of the | |
13 /// wrapped [Future] once it's completed. | |
14 class ResultFuture<T> extends DelegatingFuture<T> { | |
15 /// The wrapped [Future]. | |
16 Future<T> _future; | |
17 | |
18 /// Whether the future has fired and [result] is available. | |
19 bool get hasResult => result != null; | |
Lasse Reichstein Nielsen
2015/07/09 11:18:20
I prefer isComplete - that's the direct question,
nweiz
2015/07/13 20:05:52
Done.
| |
20 | |
21 /// The result of the wrapped [Future], if it's completed. | |
22 /// | |
23 /// If it hasn't completed yet, this will be `null`. | |
24 Result<T> get result => _result; | |
25 Result<T> _result; | |
26 | |
27 factory ResultFuture(Future<T> future) { | |
28 var resultFuture; | |
29 resultFuture = new ResultFuture._(Result.capture(future).then((result) { | |
30 resultFuture._result = result; | |
31 return result.asFuture; | |
32 })); | |
33 return resultFuture; | |
34 } | |
35 | |
36 ResultFuture._(Future<T> future) | |
37 : super(future); | |
38 } | |
OLD | NEW |