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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 * completes no sooner than in the next event-loop iteration. | 142 * completes no sooner than in the next event-loop iteration. |
143 * | 143 * |
144 * If [computation] is not given or [:null:] then it will behave as if | 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 | 145 * [computation] was set to [:() => null:]. That is, it will complete with |
146 * [:null:]. | 146 * [:null:]. |
147 * | 147 * |
148 * If calling [computation] throws, the created future will complete with the | 148 * If calling [computation] throws, the created future will complete with the |
149 * error. | 149 * error. |
150 * | 150 * |
151 * 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]. | |
155 */ | 152 */ |
156 factory Future.delayed(var duration, [T computation()]) { | 153 factory Future.delayed(Duration duration, [T computation()]) { |
157 // TODO(floitsch): no need to allocate a ThenFuture when the computation is | 154 // TODO(floitsch): no need to allocate a ThenFuture when the computation is |
158 // null. | 155 // null. |
159 if (computation == null) computation = (() => null); | 156 if (computation == null) computation = (() => null); |
160 _ThenFuture<dynamic, T> future = | 157 _ThenFuture<dynamic, T> future = |
161 new _ThenFuture<dynamic, T>((_) => computation()); | 158 new _ThenFuture<dynamic, T>((_) => computation()); |
162 new Timer(duration, () => future._sendValue(null)); | 159 new Timer(duration, () => future._sendValue(null)); |
163 return future; | 160 return future; |
164 } | 161 } |
165 | 162 |
166 /** | 163 /** |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 * The argument [exception] should not be `null`. | 353 * The argument [exception] should not be `null`. |
357 * | 354 * |
358 * If [exception] is an [AsyncError], it is used directly as the error | 355 * If [exception] is an [AsyncError], it is used directly as the error |
359 * message sent to the future's listeners, and [stackTrace] is ignored. | 356 * message sent to the future's listeners, and [stackTrace] is ignored. |
360 * | 357 * |
361 * Otherwise the [exception] and an optional [stackTrace] is combined into an | 358 * Otherwise the [exception] and an optional [stackTrace] is combined into an |
362 * [AsyncError] and sent to this future's listeners. | 359 * [AsyncError] and sent to this future's listeners. |
363 */ | 360 */ |
364 void completeError(Object exception, [Object stackTrace]); | 361 void completeError(Object exception, [Object stackTrace]); |
365 } | 362 } |
OLD | NEW |