From df26a93893518cac73bc3d5bf2a4af1f996e7fa8 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 17 Mar 2024 18:59:57 +0800 Subject: [PATCH] add one step in async --- dart-js/out.js | 26 ++++++++++++++++++++++++++ dart-js/test.dart | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/dart-js/out.js b/dart-js/out.js index 2e117b0..ea14dd2 100644 --- a/dart-js/out.js +++ b/dart-js/out.js @@ -3639,6 +3639,28 @@ return H.setRuntimeTypeInfo([], t1); return H.setRuntimeTypeInfo(["a", "b", "c"], t1); }, + b_run: function () { + var $async$goto = 0, + $async$completer = P._makeAsyncAwaitCompleter(type$.dynamic); + var $async$b_run = P._wrapJsFunctionForAsync(function ($async$errorCode, $async$result) { + if ($async$errorCode === 1) + return P._asyncRethrow($async$result, $async$completer); + while (true) + switch ($async$goto) { + case 0: + // Function start + P.print("object in b_run"); + $async$goto = 2; + return P._asyncAwait(V.md5run(), $async$b_run); + case 2: + // returning from await. + P.print("object after 1s"); + // implicit return + return P._asyncReturn(null, $async$completer); + } + }); + return P._asyncStartSync($async$b_run, $async$completer); + }, md5run: function () { var $async$goto = 0, $async$completer = P._makeAsyncAwaitCompleter(type$.dynamic); @@ -3675,6 +3697,10 @@ $async$goto = 2; return P._asyncAwait(V.md5run(), $async$a_run); case 2: + // returning from await. + $async$goto = 3; + return P._asyncAwait(V.b_run(), $async$a_run); + case 3: // returning from await. P.print("object after 1s"); // implicit return diff --git a/dart-js/test.dart b/dart-js/test.dart index 6dbfd09..bd77dd8 100644 --- a/dart-js/test.dart +++ b/dart-js/test.dart @@ -63,6 +63,12 @@ List test_list(String str) { } +b_run() async { + print("object in b_run"); + await md5run(); + print("object after 1s"); +} + md5run() async{ print("object in md5run"); await Future.delayed(Duration(milliseconds: 1000)); @@ -72,6 +78,7 @@ md5run() async{ a_run() async{ print("object"); await md5run(); + await b_run(); print("object after 1s"); }