Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Unified Diff: sdk/lib/async/future.dart

Issue 91213002: Add Future.timeout. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update indentation. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/error_group.dart ('k') | sdk/lib/async/future_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/future.dart
diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart
index 593a775d7f59461f7cda8dcc6cacabb4b316faae..db26cee4adf311433b4754986f0dba4bfb92edb6 100644
--- a/sdk/lib/async/future.dart
+++ b/sdk/lib/async/future.dart
@@ -408,6 +408,33 @@ abstract class Future<T> {
* its subscribers. The stream closes after the completion value.
*/
Stream<T> asStream();
+
+ /**
+ * Time-out the future computation after [timeLimit] has passed.
+ *
+ * Returns a new future that completes with the same value as this future,
+ * if this future completes in time.
+ *
+ * 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.
+ *
+ * If `onTimeout` is omitted, a timeout will cause the returned future to
+ * complete with a [TimeoutException].
+ */
+ Future timeout(Duration timeLimit, [void onTimeout()]);
+}
+
+/**
+ * Thrown when a scheduled timeout happens while waiting for an async result.
+ */
+class TimeoutException implements Exception {
+ /** The duration that was exceeded without a result. */
+ final Duration duration;
+
+ TimeoutException(this.duration);
+
+ String toString() => "Timeout after $duration";
}
/**
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/error_group.dart ('k') | sdk/lib/async/future_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698