summaryrefslogtreecommitdiff
path: root/core/modules.rs
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 /core/modules.rs
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 'core/modules.rs')
-rw-r--r--core/modules.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/core/modules.rs b/core/modules.rs
index 130becab8..e12699ca9 100644
--- a/core/modules.rs
+++ b/core/modules.rs
@@ -667,7 +667,7 @@ mod tests {
let a_id_fut = runtime.load_module(&spec, None);
let a_id = futures::executor::block_on(a_id_fut).expect("Failed to load");
- runtime.mod_evaluate(a_id).unwrap();
+ futures::executor::block_on(runtime.mod_evaluate(a_id)).unwrap();
let l = loads.lock().unwrap();
assert_eq!(
l.to_vec(),
@@ -734,7 +734,7 @@ mod tests {
let result = runtime.load_module(&spec, None).await;
assert!(result.is_ok());
let circular1_id = result.unwrap();
- runtime.mod_evaluate(circular1_id).unwrap();
+ runtime.mod_evaluate(circular1_id).await.unwrap();
let l = loads.lock().unwrap();
assert_eq!(
@@ -811,7 +811,7 @@ mod tests {
println!(">> result {:?}", result);
assert!(result.is_ok());
let redirect1_id = result.unwrap();
- runtime.mod_evaluate(redirect1_id).unwrap();
+ runtime.mod_evaluate(redirect1_id).await.unwrap();
let l = loads.lock().unwrap();
assert_eq!(
l.to_vec(),
@@ -961,7 +961,7 @@ mod tests {
let main_id =
futures::executor::block_on(main_id_fut).expect("Failed to load");
- runtime.mod_evaluate(main_id).unwrap();
+ futures::executor::block_on(runtime.mod_evaluate(main_id)).unwrap();
let l = loads.lock().unwrap();
assert_eq!(