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

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

Issue 12224081: Change Future.delayed to take a Duration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments and made argument optional. Created 7 years, 10 months 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 | « pkg/oauth2/lib/src/utils.dart ('k') | sdk/lib/core/duration.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 efa4144186a14e2a2a9536ac506e2ee5494365f0..820ba0087d17181fbc5b5d92e6bfdad8b51a4906 100644
--- a/sdk/lib/async/future.dart
+++ b/sdk/lib/async/future.dart
@@ -137,19 +137,29 @@ abstract class Future<T> {
/**
* Creates a future that completes after a delay.
*
- * The future will be completed after [milliseconds] have passed with
- * the result of calling [value]. If [milliseconds] is 0, it completes at the
- * earliest in the next event-loop iteration.
+ * The future will be completed after the given [duration] has passed with
+ * the result of calling [computation]. If the duration is 0 or less, it
+ * completes no sooner than in the next event-loop iteration.
*
- * If calling [value] throws, the created future will complete with the
+ * If [computation] is not given or [:null:] then it will behave as if
+ * [computation] was set to [:() => null:]. That is, it will complete with
+ * [:null:].
+ *
+ * If calling [computation] throws, the created future will complete with the
* error.
*
* See [Completer]s, for futures with values that are computed asynchronously.
+ *
+ * *Deprecation note*: this method initially took an [int] as argument (the
+ * milliseconds to wait). It is now a [Duration].
*/
- factory Future.delayed(int milliseconds, T value()) {
+ factory Future.delayed(var duration, [T computation()]) {
+ // TODO(floitsch): no need to allocate a ThenFuture when the computation is
+ // null.
+ if (computation == null) computation = (() => null);
_ThenFuture<dynamic, T> future =
- new _ThenFuture<dynamic, T>((_) => value());
- new Timer(milliseconds, (_) => future._sendValue(null));
+ new _ThenFuture<dynamic, T>((_) => computation());
+ new Timer(duration, () => future._sendValue(null));
return future;
}
« no previous file with comments | « pkg/oauth2/lib/src/utils.dart ('k') | sdk/lib/core/duration.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698