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

Unified Diff: runtime/lib/async_patch.dart

Issue 2478703003: Run async immediately in dart2js and VM. (Closed)
Patch Set: Also run sync in VM. Created 3 years, 4 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: runtime/lib/async_patch.dart
diff --git a/runtime/lib/async_patch.dart b/runtime/lib/async_patch.dart
index 7186eb094c12622af2c48814a34f6a46a5c23701..cbd16be51062f999cb348b75b37bbb8dec5afbd0 100644
--- a/runtime/lib/async_patch.dart
+++ b/runtime/lib/async_patch.dart
@@ -7,6 +7,41 @@ import "dart:_internal" hide Symbol;
// Equivalent of calling FATAL from C++ code.
_fatal(msg) native "DartAsync_fatal";
+class _AsyncAwaitCompleter<T> implements Completer<T> {
+ final _completer = new Completer<T>.sync();
+ bool isSync;
+
+ _AsyncAwaitCompleter() : isSync = false;
+
+ void complete([T value]) {
+ if (isSync) {
+ _completer.complete(value);
+ } else {
+ scheduleMicrotask(() {
+ _completer.complete(value);
+ });
+ }
+ }
+
+ void completeError(e, [st]) {
+ if (isSync) {
+ _completer.completeError(e, st);
+ } else {
+ scheduleMicrotask(() {
+ _completer.completeError(e, st);
+ });
+ }
+ }
+
+ void start(f) {
+ f();
+ isSync = true;
+ }
+
+ Future<T> get future => _completer.future;
+ bool get isCompleted => _completer.isCompleted;
+}
+
// We need to pass the value as first argument and leave the second and third
// arguments empty (used for error handling).
// See vm/ast_transformer.cc for usage.

Powered by Google App Engine
This is Rietveld 408576698