diff options
Diffstat (limited to 'runtime/web_worker.rs')
-rw-r--r-- | runtime/web_worker.rs | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index ca11cc18f..064195cd8 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -514,24 +514,26 @@ impl WebWorker { Ok(()) } - /// Loads and instantiates specified JavaScript module - /// as "main" or "side" module. - pub async fn preload_module( + /// Loads and instantiates specified JavaScript module as "main" module. + pub async fn preload_main_module( &mut self, module_specifier: &ModuleSpecifier, - main: bool, ) -> Result<ModuleId, AnyError> { - if main { - self - .js_runtime - .load_main_module(module_specifier, None) - .await - } else { - self - .js_runtime - .load_side_module(module_specifier, None) - .await - } + self + .js_runtime + .load_main_module(module_specifier, None) + .await + } + + /// Loads and instantiates specified JavaScript module as "side" module. + pub async fn preload_side_module( + &mut self, + module_specifier: &ModuleSpecifier, + ) -> Result<ModuleId, AnyError> { + self + .js_runtime + .load_side_module(module_specifier, None) + .await } /// Loads, instantiates and executes specified JavaScript module. @@ -542,7 +544,7 @@ impl WebWorker { &mut self, module_specifier: &ModuleSpecifier, ) -> Result<(), AnyError> { - let id = self.preload_module(module_specifier, false).await?; + let id = self.preload_side_module(module_specifier).await?; let mut receiver = self.js_runtime.mod_evaluate(id); tokio::select! { biased; @@ -700,7 +702,7 @@ pub fn run_web_worker( } else { // TODO(bartlomieju): add "type": "classic", ie. ability to load // script instead of module - match worker.preload_module(&specifier, true).await { + match worker.preload_main_module(&specifier).await { Ok(id) => { worker.start_polling_for_messages(); worker.execute_main_module(id).await |