summaryrefslogtreecommitdiff
path: root/cli/tests/tla3
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-10-14 14:04:09 +0200
committerGitHub <noreply@github.com>2020-10-14 14:04:09 +0200
commit135053486c4bd112ebd7d0b25c94a8dd346472e6 (patch)
tree24eae514d8de332a0968de869172f651b30b5078 /cli/tests/tla3
parent10654fa95553866c63a56a7f84c7ec47fb7aac9c (diff)
fix: top-level-await module execution (#7946)
This commit changes implementation of top-level-await in "deno_core". Previously promise returned from module evaluation was not awaited, leading to out-of-order execution of modules that have TLA. It's been fixed by changing "JsRuntime::mod_evaluate" to be an async function that resolves when the promise returned from module evaluation also resolves. When waiting for promise resolution event loop is polled repeatedly, until there are no more dynamic imports or pending ops.
Diffstat (limited to 'cli/tests/tla3')
-rw-r--r--cli/tests/tla3/b.js7
-rw-r--r--cli/tests/tla3/timeout_loop.js23
2 files changed, 30 insertions, 0 deletions
diff --git a/cli/tests/tla3/b.js b/cli/tests/tla3/b.js
new file mode 100644
index 000000000..b74c659e4
--- /dev/null
+++ b/cli/tests/tla3/b.js
@@ -0,0 +1,7 @@
+import { foo } from "./timeout_loop.js";
+import { collection } from "../top_level_await_circular.js";
+
+console.log("collection in b", collection);
+console.log("foo in b", foo);
+
+export const a = "a";
diff --git a/cli/tests/tla3/timeout_loop.js b/cli/tests/tla3/timeout_loop.js
new file mode 100644
index 000000000..860e6cd2a
--- /dev/null
+++ b/cli/tests/tla3/timeout_loop.js
@@ -0,0 +1,23 @@
+export const foo = "foo";
+
+export function delay(ms) {
+ return new Promise((res) =>
+ setTimeout(() => {
+ res();
+ }, ms)
+ );
+}
+
+let i = 0;
+
+async function timeoutLoop() {
+ await delay(1000);
+ console.log("timeout loop", i);
+ i++;
+ if (i > 5) {
+ return;
+ }
+ timeoutLoop();
+}
+
+timeoutLoop();