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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/async/future.dart
diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart
index 7219719d944f713d878d11e54f0748016c9df709..59f0efb357192cbc874136944f25a61cd9738968 100644
--- a/sdk/lib/async/future.dart
+++ b/sdk/lib/async/future.dart
@@ -343,7 +343,38 @@ abstract class Future<T> {
*/
abstract class Completer<T> {
- factory Completer() => new _CompleterImpl<T>();
+ factory Completer() => new _AsyncCompleter<T>();
+
+ /**
+ * Completes the future synchronously.
+ *
+ * This constructor should be avoided unless the completion of the future is
+ * known to be the final result of another asynchronous operation. If in doubt
+ * use the default [Completer] constructor.
+ *
+ * Example:
+ *
+ * var completer = new Completer.sync();
+ * // The completion is the result of the asynchronous onDone event.
+ * // No other operation is performed after the completion. It is safe
+ * // to use the Completer.sync constructor.
+ * stream.listen(print, onDone: () { completer.complete("done"); });
+ *
+ * Bad example. Do not use this code. Only for illustrative purposes:
+ *
+ * var completer = new Completer.sync();
+ * // The completion is the result of the asynchronous onDone event.
+ * // However, there is still code executed after the completion. This
+ * // operation is *not* safe.
+ * stream.listen(print, onDone: () {
+ * completer.complete("done");
+ * foo(); // This operation follows the completion.
+ * });
+ *
+ * *WARNING* This constructor is experimental and could disappear or change
+ * behavior.
+ */
+ factory Completer.sync() => new _SyncCompleter<T>();
/** The future that will contain the result provided to this completer. */
Future get future;

Powered by Google App Engine
This is Rietveld 408576698