Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: sdk/lib/async/future.dart

Issue 14690009: Make Completers asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 * // later when value is available, call: 336 * // later when value is available, call:
337 * completer.complete(value); 337 * completer.complete(value);
338 * 338 *
339 * // alternatively, if the service cannot produce the value, it 339 * // alternatively, if the service cannot produce the value, it
340 * // can provide an error: 340 * // can provide an error:
341 * completer.completeError(error); 341 * completer.completeError(error);
342 * 342 *
343 */ 343 */
344 abstract class Completer<T> { 344 abstract class Completer<T> {
345 345
346 factory Completer() => new _CompleterImpl<T>(); 346 factory Completer() => new _AsyncCompleter<T>();
347
348 /**
349 * Completes the future synchronously.
350 *
351 * This constructor should be avoided unless the completion of the future is
352 * known to be the final result of another asynchronous operation. If in doubt
353 * use the default [Completer] constructor.
354 *
355 * Example:
356 *
357 * var completer = new Completer.sync();
358 * // The completion is the result of the asynchronous onDone event.
359 * // No other operation is performed after the completion. It is safe
360 * // to use the Completer.sync constructor.
361 * stream.listen(print, onDone: () { completer.complete("done"); });
362 *
363 * Bad example. Do not use this code. Only for illustrative purposes:
364 *
365 * var completer = new Completer.sync();
366 * // The completion is the result of the asynchronous onDone event.
367 * // However, there is still code executed after the completion. This
368 * // operation is *not* safe.
369 * stream.listen(print, onDone: () {
370 * completer.complete("done");
371 * foo(); // This operation follows the completion.
372 * });
373 *
374 * *WARNING* This constructor is experimental and could disappear or change
375 * behavior.
376 */
377 factory Completer.sync() => new _SyncCompleter<T>();
347 378
348 /** The future that will contain the result provided to this completer. */ 379 /** The future that will contain the result provided to this completer. */
349 Future get future; 380 Future get future;
350 381
351 /** 382 /**
352 * Completes [future] with the supplied values. 383 * Completes [future] with the supplied values.
353 * 384 *
354 * All listeners on the future will be immediately informed about the value. 385 * All listeners on the future will be immediately informed about the value.
355 */ 386 */
356 void complete([T value]); 387 void complete([T value]);
357 388
358 /** 389 /**
359 * Complete [future] with an error. 390 * Complete [future] with an error.
360 * 391 *
361 * Completing a future with an error indicates that an exception was thrown 392 * Completing a future with an error indicates that an exception was thrown
362 * while trying to produce a value. 393 * while trying to produce a value.
363 * 394 *
364 * The argument [exception] should not be `null`. 395 * The argument [exception] should not be `null`.
365 */ 396 */
366 void completeError(Object exception, [Object stackTrace]); 397 void completeError(Object exception, [Object stackTrace]);
367 398
368 /** 399 /**
369 * Whether the future has been completed. 400 * Whether the future has been completed.
370 */ 401 */
371 bool get isCompleted; 402 bool get isCompleted;
372 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698