mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 08:59:24 +00:00
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:
parent
fa08150ca6
commit
963f653b12
|
@ -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()});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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, () {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue