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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 * Returns a new [Future] `f` which is completed with the result of | 258 * Returns a new [Future] `f` which is completed with the result of |
259 * invoking [onValue] (if [this] completes with a value) or [onError] (if | 259 * invoking [onValue] (if [this] completes with a value) or [onError] (if |
260 * [this] completes with an error). | 260 * [this] completes with an error). |
261 * | 261 * |
262 * If the invoked callback throws an exception, the returned future `f` is | 262 * If the invoked callback throws an exception, the returned future `f` is |
263 * completed with the error. | 263 * completed with the error. |
264 * | 264 * |
265 * If the invoked callback returns a [Future] `f2` then `f` and `f2` are | 265 * If the invoked callback returns a [Future] `f2` then `f` and `f2` are |
266 * chained. That is, `f` is completed with the completion value of `f2`. | 266 * chained. That is, `f` is completed with the completion value of `f2`. |
267 * | 267 * |
268 * If [onError] is not given, it is equivalent to `(e) { throw e; }`. That | 268 * The [onError] callback must be of type `void onError(error)` or |
269 * is, it forwards the error to `f`. | 269 * `void onError(error, StackTrace stackTrace)`. If [onError] accepts |
| 270 * two arguments it is called with the stack trace (which could be `null` if |
| 271 * the stream itself received an error without stack trace). |
| 272 * Otherwise it is called with just the error object. |
| 273 * |
| 274 * If [onError] is not given it forwards the error to `f`. |
270 * | 275 * |
271 * In most cases, it is more readable to use [catchError] separately, possibly | 276 * In most cases, it is more readable to use [catchError] separately, possibly |
272 * with a `test` parameter, instead of handling both value and error in a | 277 * with a `test` parameter, instead of handling both value and error in a |
273 * single [then] call. | 278 * single [then] call. |
274 */ | 279 */ |
275 Future then(onValue(T value), { onError(Object error) }); | 280 Future then(onValue(T value), { Function onError }); |
276 | 281 |
277 /** | 282 /** |
278 * Handles errors emitted by this [Future]. | 283 * Handles errors emitted by this [Future]. |
279 * | 284 * |
280 * Returns a new [Future] `f`. | 285 * Returns a new [Future] `f`. |
281 * | 286 * |
282 * When [this] completes with a value, the value is forwarded to `f` | 287 * When [this] completes with a value, the value is forwarded to `f` |
283 * unmodified. That is, `f` completes with the same value. | 288 * unmodified. That is, `f` completes with the same value. |
284 * | 289 * |
285 * When [this] completes with an error, [test] is called with the | 290 * When [this] completes with an error, [test] is called with the |
(...skipping 12 matching lines...) Expand all Loading... |
298 * .catchError(..., test: (e) => e is ArgumentError) | 303 * .catchError(..., test: (e) => e is ArgumentError) |
299 * .catchError(..., test: (e) => e is NoSuchMethodError) | 304 * .catchError(..., test: (e) => e is NoSuchMethodError) |
300 * .then((v) { ... }); | 305 * .then((v) { ... }); |
301 * | 306 * |
302 * This method is equivalent to: | 307 * This method is equivalent to: |
303 * | 308 * |
304 * Future catchError(onError(error), | 309 * Future catchError(onError(error), |
305 * {bool test(error)}) { | 310 * {bool test(error)}) { |
306 * this.then((v) => v, // Forward the value. | 311 * this.then((v) => v, // Forward the value. |
307 * // But handle errors, if the [test] succeeds. | 312 * // But handle errors, if the [test] succeeds. |
308 * onError: (e) { | 313 * onError: (e, stackTrace) { |
309 * if (test == null || test(e)) { | 314 * if (test == null || test(e)) { |
| 315 * if (onError is ZoneBinaryCallback) { |
| 316 * return onError(e, stackTrace); |
| 317 * } |
310 * return onError(e); | 318 * return onError(e); |
311 * } | 319 * } |
312 * throw e; | 320 * throw e; |
313 * }); | 321 * }); |
314 * } | 322 * } |
315 * | 323 * |
316 */ | 324 */ |
317 Future catchError(onError(Object error), | 325 Future catchError(Function onError, |
318 {bool test(Object error)}); | 326 {bool test(Object error)}); |
319 | 327 |
320 /** | 328 /** |
321 * Register a function to be called when this future completes. | 329 * Register a function to be called when this future completes. |
322 * | 330 * |
323 * The [action] function is called when this future completes, whether it | 331 * The [action] function is called when this future completes, whether it |
324 * does so with a value or with an error. | 332 * does so with a value or with an error. |
325 * | 333 * |
326 * This is the asynchronous equivalent of a "finally" block. | 334 * This is the asynchronous equivalent of a "finally" block. |
327 * | 335 * |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 * | 476 * |
469 * The argument [exception] must not be `null`. | 477 * The argument [exception] must not be `null`. |
470 */ | 478 */ |
471 void completeError(Object exception, [Object stackTrace]); | 479 void completeError(Object exception, [Object stackTrace]); |
472 | 480 |
473 /** | 481 /** |
474 * Whether the future has been completed. | 482 * Whether the future has been completed. |
475 */ | 483 */ |
476 bool get isCompleted; | 484 bool get isCompleted; |
477 } | 485 } |
OLD | NEW |