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

Unified Diff: sdk/lib/_internal/js_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
« pkg/compiler/lib/src/common_elements.dart ('K') | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/js_runtime/lib/async_patch.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/async_patch.dart b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
index ce7b0d1e838846313c059124ede83db951e4db02..6e96ac48d7bbf7e90754830d93feefc6de50a561 100644
--- a/sdk/lib/_internal/js_runtime/lib/async_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
@@ -130,6 +130,36 @@ class Timer {
}
}
+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);
+ });
+ }
+ }
+
+ Future<T> get future => _completer.future;
+ bool get isCompleted => _completer.isCompleted;
+}
+
/// Initiates the computation of an `async` function.
///
/// Used as part of the runtime support for the async/await transformation.
@@ -137,9 +167,14 @@ class Timer {
/// This function sets up the first call into the transformed [bodyFunction].
/// Independently, it takes the [completer] and returns the future of the
/// completer for convenience of the transformed code.
-dynamic _asyncStart(_WrappedAsyncBody bodyFunction, Completer completer) {
- // TODO(sra): Specialize this implementation of `await null`.
- _awaitOnObject(null, bodyFunction);
+dynamic _asyncStart(
+ _WrappedAsyncBody bodyFunction, _AsyncAwaitCompleter completer) {
+ if (completer.isSync) {
+ // Can't happen. Just here to make the class known to the compiler.
sra1 2017/08/24 17:21:18 This should be done properly through the impact sy
+ completer = new _AsyncAwaitCompleter();
+ }
+ bodyFunction(async_error_codes.SUCCESS, null);
+ completer.isSync = true;
return completer.future;
}
« pkg/compiler/lib/src/common_elements.dart ('K') | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698