Chromium Code Reviews| 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; |
| } |