Make generic type of timeout-future the same as the one from the original.

R=lrn@google.com

Review URL: https://codereview.chromium.org//1299443002 .
This commit is contained in:
Florian Loitsch 2016-02-09 18:57:25 +01:00
parent fa08150ca6
commit 963f653b12
3 changed files with 14 additions and 3 deletions

View file

@ -546,11 +546,12 @@ abstract class Future<T> {
* If this future does not complete before `timeLimit` has passed,
* the [onTimeout] action is executed instead, and its result (whether it
* returns or throws) is used as the result of the returned future.
* The [onTimeout] function must return a [T] or a `Future<T>`.
*
* If `onTimeout` is omitted, a timeout will cause the returned future to
* complete with a [TimeoutException].
*/
Future timeout(Duration timeLimit, {onTimeout()});
Future<T> timeout(Duration timeLimit, {onTimeout()});
}
/**

View file

@ -680,9 +680,9 @@ class _Future<T> implements Future<T> {
}
}
Future timeout(Duration timeLimit, {onTimeout()}) {
Future<T> timeout(Duration timeLimit, {onTimeout()}) {
if (_isComplete) return new _Future.immediate(this);
_Future result = new _Future();
_Future result = new _Future<T>();
Timer timer;
if (onTimeout == null) {
timer = new Timer(timeLimit, () {

View file

@ -185,4 +185,14 @@ main() {
expect(s, null);
}));
});
test("timeoutType", () {
Completer completer = new Completer<int>();
Future timedOut = completer.future.timeout(
const Duration(milliseconds: 5));
expect(timedOut, new isInstanceOf<Future<int>>());
expect(timedOut, isNot(new isInstanceOf<Future<String>>()));
timedOut.catchError((_) {});
completer.complete(499);
});
}