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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import '../typed/future.dart'; | |
8 | |
7 /// A wrapper that forwards calls to a [Future]. | 9 /// A wrapper that forwards calls to a [Future]. |
8 class DelegatingFuture<T> implements Future<T> { | 10 class DelegatingFuture<T> implements Future<T> { |
9 /// The wrapped [Future]. | 11 /// The wrapped [Future]. |
10 final Future<T> _future; | 12 final Future<T> _future; |
11 | 13 |
12 DelegatingFuture(this._future); | 14 DelegatingFuture(this._future); |
13 | 15 |
16 /// Creates a wrapper that asserts the types of the value emitted by [future]. | |
Lasse Reichstein Nielsen
2016/04/08 09:20:29
"asserts" isn't clear.
Maybe:
Creates a `Future
nweiz
2016/04/11 20:26:16
Done.
| |
17 /// | |
18 /// This soundly converts a [Future] without a generic type to a `Future<T>` | |
Lasse Reichstein Nielsen
2016/04/08 09:20:29
You can't have a Future without a generic type - t
nweiz
2016/04/11 20:26:16
Done.
| |
19 /// by asserting that its value is an instance of `T` whenever it's accessed. | |
Lasse Reichstein Nielsen
2016/04/08 09:20:29
You don't "access" a future value, it's push, not
nweiz
2016/04/11 20:26:16
Done.
| |
20 /// If it's not, it throws a [CastError]. | |
Lasse Reichstein Nielsen
2016/04/08 09:20:29
Two "it"s referring to different things in the sam
nweiz
2016/04/11 20:26:16
Done.
| |
21 static Future/*<T>*/ typed/*<T>*/(Future future) => | |
22 future is Future/*<T>*/ ? future : new TypeSafeFuture/*<T>*/(future); | |
23 | |
14 Stream<T> asStream() => _future.asStream(); | 24 Stream<T> asStream() => _future.asStream(); |
15 | 25 |
16 Future catchError(Function onError, {bool test(Object error)}) => | 26 Future catchError(Function onError, {bool test(Object error)}) => |
17 _future.catchError(onError, test: test); | 27 _future.catchError(onError, test: test); |
18 | 28 |
19 Future/*<S>*/ then/*<S>*/(/*=S*/ onValue(T value), {Function onError}) => | 29 Future/*<S>*/ then/*<S>*/(/*=S*/ onValue(T value), {Function onError}) => |
20 _future.then(onValue, onError: onError); | 30 _future.then(onValue, onError: onError); |
21 | 31 |
22 Future<T> whenComplete(action()) => _future.whenComplete(action); | 32 Future<T> whenComplete(action()) => _future.whenComplete(action); |
23 | 33 |
24 Future<T> timeout(Duration timeLimit, {void onTimeout()}) => | 34 Future<T> timeout(Duration timeLimit, {onTimeout()}) => |
25 _future.timeout(timeLimit, onTimeout: onTimeout); | 35 _future.timeout(timeLimit, onTimeout: onTimeout); |
26 } | 36 } |
OLD | NEW |