| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return new Future<T>.value(result); | 131 return new Future<T>.value(result); |
| 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<T>.sync(() => value):]. |
| 142 * | 142 * |
| 143 * See [Completer] to create a Future and complete it later. | 143 * See [Completer] to create a Future and complete it later. |
| 144 */ | 144 */ |
| 145 factory Future.value([T value]) { | 145 factory Future.value([value]) { |
| 146 return new _Future<T>.immediate(value); | 146 return new _Future<T>.immediate(value); |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * A future that completes with an error in the next event-loop iteration. | 150 * A future that completes with an error in the next event-loop iteration. |
| 151 * | 151 * |
| 152 * See [Completer] to create a Future and complete it later. | 152 * See [Completer] to create a Future and complete it later. |
| 153 */ | 153 */ |
| 154 factory Future.error(var error, [Object stackTrace]) { | 154 factory Future.error(var error, [Object stackTrace]) { |
| 155 return new _Future<T>.immediateError(error, stackTrace); | 155 return new _Future<T>.immediateError(error, stackTrace); |
| (...skipping 202 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 |