Chromium Code Reviews| 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 * An object representing a delayed computation. | 8 * An object representing a delayed computation. |
| 9 * | 9 * |
| 10 * A [Future] is used to obtain a not yet | 10 * A [Future] is used to obtain a not yet |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 * error. If a thrown value is an [AsyncError], it is used | 121 * error. If a thrown value is an [AsyncError], it is used |
| 122 * directly, instead of wrapping this error again in another [AsyncError]. | 122 * directly, instead of wrapping this error again in another [AsyncError]. |
| 123 * | 123 * |
| 124 * If the returned value is itself a [Future], completion of | 124 * If the returned value is itself a [Future], completion of |
| 125 * the created future will wait until the returned future completes, | 125 * the created future will wait until the returned future completes, |
| 126 * and will then complete with the same result. | 126 * and will then complete with the same result. |
| 127 */ | 127 */ |
| 128 factory Future.sync(computation()) { | 128 factory Future.sync(computation()) { |
| 129 try { | 129 try { |
| 130 var result = computation(); | 130 var result = computation(); |
| 131 return new Future<T>.value(result); | 131 return new Future.value(result); |
|
kevmoo-old
2013/09/17 17:21:41
After I did the update, I decided I don't like thi
floitsch
2013/09/17 17:59:44
This Future<T> is correct. But the Future.value sh
| |
| 132 } catch (error, stackTrace) { | 132 } catch (error, stackTrace) { |
| 133 return new Future<T>.error(error, stackTrace); | 133 return new Future<T>.error(error, stackTrace); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 /** | 137 /** |
| 138 * A future whose value is available in the next event-loop iteration. | 138 * A future whose value is available in the next event-loop iteration. |
| 139 * | 139 * |
| 140 * If [value] is not a [Future], using this constructor is equivalent | 140 * If [value] is not a [Future], using this constructor is equivalent |
| 141 * to [:new Future.sync(() => value):]. | 141 * to [:new Future.sync(() => value):]. |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 */ | 358 */ |
| 359 Stream<T> asStream(); | 359 Stream<T> asStream(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * A way to produce Future objects and to complete them later | 363 * A way to produce Future objects and to complete them later |
| 364 * with a value or error. | 364 * with a value or error. |
| 365 * | 365 * |
| 366 * If you already have a Future, you probably don't need a Completer. | 366 * If you already have a Future, you probably don't need a Completer. |
| 367 * Instead, you can usually use [Future.then], which returns a Future: | 367 * Instead, you can usually use [Future.then], which returns a Future: |
| 368 * | 368 * |
| 369 * Future doStuff(){ | 369 * Future doStuff(){ |
| 370 * return someAsyncOperation().then((result) { | 370 * return someAsyncOperation().then((result) { |
| 371 * // Do something. | 371 * // Do something. |
| 372 * }); | 372 * }); |
| 373 * } | 373 * } |
| 374 * | 374 * |
| 375 * If you do need to create a Future from scratch—for example, | 375 * If you do need to create a Future from scratch—for example, |
| 376 * when you're converting a callback-based API into a Future-based | 376 * when you're converting a callback-based API into a Future-based |
| 377 * one—you can use a Completer as follows: | 377 * one—you can use a Completer as follows: |
| 378 * | 378 * |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 * | 465 * |
| 466 * The argument [exception] must not be `null`. | 466 * The argument [exception] must not be `null`. |
| 467 */ | 467 */ |
| 468 void completeError(Object exception, [Object stackTrace]); | 468 void completeError(Object exception, [Object stackTrace]); |
| 469 | 469 |
| 470 /** | 470 /** |
| 471 * Whether the future has been completed. | 471 * Whether the future has been completed. |
| 472 */ | 472 */ |
| 473 bool get isCompleted; | 473 bool get isCompleted; |
| 474 } | 474 } |
| OLD | NEW |