OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 class TypeSafeFuture<T> implements Future<T> { | 7 class TypeSafeFuture<T> implements Future<T> { |
8 final Future _future; | 8 final Future _future; |
9 | 9 |
10 TypeSafeFuture(this._future); | 10 TypeSafeFuture(this._future); |
11 | 11 |
12 Stream<T> asStream() => _future.then((value) => value as T).asStream(); | 12 Stream<T> asStream() => _future.then((value) => value as T).asStream(); |
13 | 13 |
14 Future catchError(Function onError, {bool test(Object error)}) => | 14 Future<T> catchError(Function onError, {bool test(Object error)}) async => |
15 _future.catchError(onError, test: test); | 15 new TypeSafeFuture<T>(_future.catchError(onError, test: test)); |
16 | 16 |
17 Future/*<S>*/ then/*<S>*/(/*=S*/ onValue(T value), {Function onError}) => | 17 Future/*<S>*/ then/*<S>*/(/*=S*/ onValue(T value), {Function onError}) => |
18 _future.then((value) => onValue(value as T), onError: onError); | 18 _future.then((value) => onValue(value as T), onError: onError); |
19 | 19 |
20 Future<T> whenComplete(action()) => | 20 Future<T> whenComplete(action()) => |
21 new TypeSafeFuture<T>(_future.whenComplete(action)); | 21 new TypeSafeFuture<T>(_future.whenComplete(action)); |
22 | 22 |
23 Future<T> timeout(Duration timeLimit, {onTimeout()}) => | 23 Future<T> timeout(Duration timeLimit, {onTimeout()}) => |
24 new TypeSafeFuture<T>(_future.timeout(timeLimit, onTimeout: onTimeout)); | 24 new TypeSafeFuture<T>(_future.timeout(timeLimit, onTimeout: onTimeout)); |
25 } | 25 } |
OLD | NEW |