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

Unified Diff: sdk/lib/async/future_impl.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_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index 3660b9ff8830910280bcf7b639f976fec9f9ca52..66ede309d520233c853830a230ea5316f133dc5c 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -7,17 +7,19 @@ part of dart.async;
deprecatedFutureValue(_FutureImpl future) =>
future._isComplete ? future._resultOrListeners : null;
-class _CompleterImpl<T> implements Completer<T> {
+abstract class _Completer<T> implements Completer<T> {
final Future<T> future;
bool _isComplete = false;
- _CompleterImpl() : future = new _FutureImpl<T>();
+ _Completer() : future = new _FutureImpl<T>();
+
+ void _setFutureValue(T value);
+ void _setFutureError(error);
void complete([T value]) {
if (_isComplete) throw new StateError("Future already completed");
_isComplete = true;
- _FutureImpl future = this.future;
- future._setValue(value);
+ _setFutureValue(value);
}
void completeError(Object error, [Object stackTrace = null]) {
@@ -27,13 +29,34 @@ class _CompleterImpl<T> implements Completer<T> {
// Force the stack trace onto the error, even if it already had one.
_attachStackTrace(error, stackTrace);
}
- _FutureImpl future = this.future;
- future._setError(error);
+ _setFutureError(error);
}
bool get isCompleted => _isComplete;
}
+class _AsyncCompleter<T> extends _Completer<T> {
+ void _setFutureValue(T value) {
+ _FutureImpl future = this.future;
+ runAsync(() { future._setValue(value); });
+ }
+
+ void _setFutureError(error) {
+ _FutureImpl future = this.future;
+ runAsync(() { future._setError(error); });
+ }
+}
+
+class _SyncCompleter<T> extends _Completer<T> {
+ void _setFutureValue(T value) {
+ future._setValue(value);
+ }
+
+ void _setFutureError(error) {
+ future._setError(error);
+ }
+}
+
/**
* A listener on a future.
*

Powered by Google App Engine
This is Rietveld 408576698