OLD | NEW |
---|---|
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 Loading... | |
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 [value]. If the duration is 0 or less, it completes |
142 * earliest in the next event-loop iteration. | 142 * at the earliest in the next event-loop iteration. |
Lasse Reichstein Nielsen
2013/02/12 14:53:10
at the earliest -> no sooner than
floitsch
2013/02/13 19:27:30
Done.
| |
143 * | 143 * |
144 * If calling [value] throws, the created future will complete with the | 144 * If calling [value] throws, the created future will complete with the |
145 * error. | 145 * error. |
146 * | 146 * |
147 * See [Completer]s, for futures with values that are computed asynchronously. | 147 * See [Completer]s, for futures with values that are computed asynchronously. |
148 * | |
149 * *Deprecation note*: this method initially took an [int] as argument (the | |
150 * milliseconds to wait). It is now a [Duration]. | |
148 */ | 151 */ |
149 factory Future.delayed(int milliseconds, T value()) { | 152 factory Future.delayed(var duration, T value()) { |
Lasse Reichstein Nielsen
2013/02/12 14:53:10
I'm not opposed to making value optional.
I don't
floitsch
2013/02/13 19:27:30
Done.
| |
150 _ThenFuture<dynamic, T> future = | 153 _ThenFuture<dynamic, T> future = |
151 new _ThenFuture<dynamic, T>((_) => value()); | 154 new _ThenFuture<dynamic, T>((_) => value()); |
152 new Timer(milliseconds, (_) => future._sendValue(null)); | 155 new Timer(duration, () => future._sendValue(null)); |
153 return future; | 156 return future; |
154 } | 157 } |
155 | 158 |
156 /** | 159 /** |
157 * Wait for all the given futures to complete and collect their values. | 160 * Wait for all the given futures to complete and collect their values. |
158 * | 161 * |
159 * Returns a future which will complete once all the futures in a list are | 162 * 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, | 163 * 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 | 164 * 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. | 165 * 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 Loading... | |
346 * The argument [exception] should not be `null`. | 349 * The argument [exception] should not be `null`. |
347 * | 350 * |
348 * If [exception] is an [AsyncError], it is used directly as the error | 351 * If [exception] is an [AsyncError], it is used directly as the error |
349 * message sent to the future's listeners, and [stackTrace] is ignored. | 352 * message sent to the future's listeners, and [stackTrace] is ignored. |
350 * | 353 * |
351 * Otherwise the [exception] and an optional [stackTrace] is combined into an | 354 * Otherwise the [exception] and an optional [stackTrace] is combined into an |
352 * [AsyncError] and sent to this future's listeners. | 355 * [AsyncError] and sent to this future's listeners. |
353 */ | 356 */ |
354 void completeError(Object exception, [Object stackTrace]); | 357 void completeError(Object exception, [Object stackTrace]); |
355 } | 358 } |
OLD | NEW |