Line data Source code
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
3 : // BSD-style license that can be found in the LICENSE file.
4 :
5 : import 'dart:async';
6 :
7 : class TypeSafeFuture<T> implements Future<T> {
8 : final Future _future;
9 :
10 0 : TypeSafeFuture(this._future);
11 :
12 0 : Stream<T> asStream() => _future.then((value) => value as T).asStream();
13 :
14 : Future<T> catchError(Function onError, {bool test(Object error)}) async =>
15 0 : new TypeSafeFuture<T>(_future.catchError(onError, test: test));
16 :
17 : Future<S> then<S>(dynamic onValue(T value), {Function onError}) =>
18 0 : _future.then((value) => onValue(value as T), onError: onError);
19 :
20 : Future<T> whenComplete(action()) =>
21 0 : new TypeSafeFuture<T>(_future.whenComplete(action));
22 :
23 : Future<T> timeout(Duration timeLimit, {onTimeout()}) =>
24 0 : new TypeSafeFuture<T>(_future.timeout(timeLimit, onTimeout: onTimeout));
25 : }
|