diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-10-06 10:18:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-06 10:18:22 +0200 |
| commit | c7c767782538243ded64742dca9b34d6af74d62d (patch) | |
| tree | e0c4cdaac58f56b09c54476d73f3d5feb419e731 /core/modules.rs | |
| parent | 40324ff74816a99ea061929ece1c6a4ff3078bc3 (diff) | |
fix(core): module execution with top level await (#7672)
This commit fixes implementation of top level await in "deno_core".
Previously promise returned from module execution was ignored causing to execute
modules out-of-order.
With this commit promise returned from module execution is stored on "JsRuntime"
and event loop is polled until the promise resolves.
Diffstat (limited to 'core/modules.rs')
| -rw-r--r-- | core/modules.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/core/modules.rs b/core/modules.rs index 235bfeb4e..a0e4fad95 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -341,6 +341,13 @@ pub struct ModuleInfo { pub name: String, pub handle: v8::Global<v8::Module>, pub import_specifiers: Vec<ModuleSpecifier>, + // TODO(bartlomieju): there should be "state" + // field that describes if module is already being loaded, + // so concurent dynamic imports don't introduce dead lock + // pub state: LoadState { + // Loading(shared_future), + // Loaded, + // }, } /// A symbolic module entity. @@ -667,7 +674,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 +741,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 +818,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 +968,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!( |
