diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-12-20 00:34:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-20 00:34:22 +0100 |
commit | e924bbdf3606e83ff9eef3a8ed640c4ecc34444f (patch) | |
tree | 19847fac129a678c1e5efa5f3495c8414146fa22 /core/modules.rs | |
parent | 660f75e066226a635375b70225df165bcf759077 (diff) |
fix: TLA in web worker (#8809)
Implementors of `deno_core::JsRuntime` might want to do additional actions
during each turn of event loop, eg. `deno_runtime::Worker` polls inspector,
`deno_runtime::WebWorker` receives/dispatches messages from/to worker host.
Previously `JsRuntime::mod_evaluate` was implemented in such fashion that it
only polled `JsRuntime`'s event loop. This behavior turned out to be wrong
in the example of `WebWorker` which couldn't receive/dispatch messages because
its implementation of event loop was never called.
This commit rewrites "mod_evaluate" to return a handle to receiver that resolves
when module's promise resolves. It is now implementors responsibility to poll
event loop after calling `mod_evaluate`.
Diffstat (limited to 'core/modules.rs')
-rw-r--r-- | core/modules.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/core/modules.rs b/core/modules.rs index 546f2464f..8248eb32d 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -718,8 +718,8 @@ mod tests { let spec = ModuleSpecifier::resolve_url("file:///a.js").unwrap(); let a_id_fut = runtime.load_module(&spec, None); let a_id = futures::executor::block_on(a_id_fut).expect("Failed to load"); - - futures::executor::block_on(runtime.mod_evaluate(a_id)).unwrap(); + runtime.mod_evaluate(a_id); + futures::executor::block_on(runtime.run_event_loop()).unwrap(); let l = loads.lock().unwrap(); assert_eq!( l.to_vec(), @@ -786,7 +786,8 @@ mod tests { let result = runtime.load_module(&spec, None).await; assert!(result.is_ok()); let circular1_id = result.unwrap(); - runtime.mod_evaluate(circular1_id).await.unwrap(); + runtime.mod_evaluate(circular1_id); + runtime.run_event_loop().await.unwrap(); let l = loads.lock().unwrap(); assert_eq!( @@ -863,7 +864,8 @@ mod tests { println!(">> result {:?}", result); assert!(result.is_ok()); let redirect1_id = result.unwrap(); - runtime.mod_evaluate(redirect1_id).await.unwrap(); + runtime.mod_evaluate(redirect1_id); + runtime.run_event_loop().await.unwrap(); let l = loads.lock().unwrap(); assert_eq!( l.to_vec(), @@ -1012,8 +1014,8 @@ mod tests { .boxed_local(); let main_id = futures::executor::block_on(main_id_fut).expect("Failed to load"); - - futures::executor::block_on(runtime.mod_evaluate(main_id)).unwrap(); + runtime.mod_evaluate(main_id); + futures::executor::block_on(runtime.run_event_loop()).unwrap(); let l = loads.lock().unwrap(); assert_eq!( |