diff options
Diffstat (limited to 'runtime/web_worker.rs')
-rw-r--r-- | runtime/web_worker.rs | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index ed7b95f5b..975028b16 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -458,21 +458,32 @@ impl WebWorker { Ok(()) } - /// Loads and instantiates specified JavaScript module. + /// Loads and instantiates specified JavaScript module + /// as "main" or "side" module. pub async fn preload_module( &mut self, module_specifier: &ModuleSpecifier, + main: bool, ) -> Result<ModuleId, AnyError> { - self.js_runtime.load_module(module_specifier, None).await + if main { + self + .js_runtime + .load_main_module(module_specifier, None) + .await + } else { + self + .js_runtime + .load_side_module(module_specifier, None) + .await + } } /// Loads, instantiates and executes specified JavaScript module. - pub async fn execute_module( + pub async fn execute_main_module( &mut self, module_specifier: &ModuleSpecifier, ) -> Result<(), AnyError> { - let id = self.preload_module(module_specifier).await?; - + let id = self.preload_module(module_specifier, true).await?; let mut receiver = self.js_runtime.mod_evaluate(id); tokio::select! { maybe_result = &mut receiver => { @@ -494,6 +505,17 @@ impl WebWorker { } } + #[deprecated( + since = "0.26.0", + note = "This method had a bug, marking multiple modules loaded as \"main\". Use `execute_main_module`." + )] + pub async fn execute_module( + &mut self, + module_specifier: &ModuleSpecifier, + ) -> Result<(), AnyError> { + self.execute_main_module(module_specifier).await + } + pub fn poll_event_loop( &mut self, cx: &mut Context, @@ -568,7 +590,7 @@ pub fn run_web_worker( } else { // TODO(bartlomieju): add "type": "classic", ie. ability to load // script instead of module - worker.execute_module(&specifier).await + worker.execute_main_module(&specifier).await }; let internal_handle = worker.internal_handle.clone(); |