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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/oauth2/lib/src/utils.dart ('k') | sdk/lib/core/duration.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 /** 7 /**
8 * A [Future] represents a delayed computation. It is used to obtain a not-yet 8 * A [Future] represents a delayed computation. It is used to obtain a not-yet
9 * available value, or error, sometime in the future. Receivers of a 9 * available value, or error, sometime in the future. Receivers of a
10 * [Future] can register callbacks that handle the value or error once it is 10 * [Future] can register callbacks that handle the value or error once it is
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 * 130 *
131 * See [Completer] to create a Future and complete it later. 131 * See [Completer] to create a Future and complete it later.
132 */ 132 */
133 factory Future.immediateError(var error, [Object stackTrace]) { 133 factory Future.immediateError(var error, [Object stackTrace]) {
134 return new _FutureImpl<T>.immediateError(error, stackTrace); 134 return new _FutureImpl<T>.immediateError(error, stackTrace);
135 } 135 }
136 136
137 /** 137 /**
138 * Creates a future that completes after a delay. 138 * Creates a future that completes after a delay.
139 * 139 *
140 * The future will be completed after [milliseconds] have passed with 140 * The future will be completed after the given [duration] has passed with
141 * the result of calling [value]. If [milliseconds] is 0, it completes at the 141 * the result of calling [computation]. If the duration is 0 or less, it
142 * earliest in the next event-loop iteration. 142 * completes no sooner than in the next event-loop iteration.
143 * 143 *
144 * If calling [value] throws, the created future will complete with the 144 * If [computation] is not given or [:null:] then it will behave as if
145 * [computation] was set to [:() => null:]. That is, it will complete with
146 * [:null:].
147 *
148 * If calling [computation] throws, the created future will complete with the
145 * error. 149 * error.
146 * 150 *
147 * See [Completer]s, for futures with values that are computed asynchronously. 151 * See [Completer]s, for futures with values that are computed asynchronously.
152 *
153 * *Deprecation note*: this method initially took an [int] as argument (the
154 * milliseconds to wait). It is now a [Duration].
148 */ 155 */
149 factory Future.delayed(int milliseconds, T value()) { 156 factory Future.delayed(var duration, [T computation()]) {
157 // TODO(floitsch): no need to allocate a ThenFuture when the computation is
158 // null.
159 if (computation == null) computation = (() => null);
150 _ThenFuture<dynamic, T> future = 160 _ThenFuture<dynamic, T> future =
151 new _ThenFuture<dynamic, T>((_) => value()); 161 new _ThenFuture<dynamic, T>((_) => computation());
152 new Timer(milliseconds, (_) => future._sendValue(null)); 162 new Timer(duration, () => future._sendValue(null));
153 return future; 163 return future;
154 } 164 }
155 165
156 /** 166 /**
157 * Wait for all the given futures to complete and collect their values. 167 * Wait for all the given futures to complete and collect their values.
158 * 168 *
159 * Returns a future which will complete once all the futures in a list are 169 * Returns a future which will complete once all the futures in a list are
160 * complete. If any of the futures in the list completes with an error, 170 * complete. If any of the futures in the list completes with an error,
161 * the resulting future also completes with an error. Otherwise the value 171 * the resulting future also completes with an error. Otherwise the value
162 * of the returned future will be a list of all the values that were produced. 172 * of the returned future will be a list of all the values that were produced.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 * The argument [exception] should not be `null`. 356 * The argument [exception] should not be `null`.
347 * 357 *
348 * If [exception] is an [AsyncError], it is used directly as the error 358 * If [exception] is an [AsyncError], it is used directly as the error
349 * message sent to the future's listeners, and [stackTrace] is ignored. 359 * message sent to the future's listeners, and [stackTrace] is ignored.
350 * 360 *
351 * Otherwise the [exception] and an optional [stackTrace] is combined into an 361 * Otherwise the [exception] and an optional [stackTrace] is combined into an
352 * [AsyncError] and sent to this future's listeners. 362 * [AsyncError] and sent to this future's listeners.
353 */ 363 */
354 void completeError(Object exception, [Object stackTrace]); 364 void completeError(Object exception, [Object stackTrace]);
355 } 365 }
OLDNEW
« 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