summaryrefslogtreecommitdiff
path: root/runtime/worker.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-08-10 18:10:51 -0400
committerGitHub <noreply@github.com>2022-08-10 18:10:51 -0400
commit321a42d1fbab8dd8869749b44b560bbbc4f5872a (patch)
tree0b2369e8cfa511250d3e32a5cbefd304edba57fe /runtime/worker.rs
parent578f12d531b146661294771f002cf0d76bcc5f9a (diff)
refactor(runtime): split up `MainWorker` and `WebWorker`'s `preload_module` method into two separate methods (#15451)
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r--runtime/worker.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs
index b8ab8b8ca..e8cddd5c9 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -217,24 +217,26 @@ impl MainWorker {
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
}
/// Executes specified JavaScript module.
@@ -242,6 +244,7 @@ impl MainWorker {
&mut self,
id: ModuleId,
) -> Result<(), AnyError> {
+ self.wait_for_inspector_session();
let mut receiver = self.js_runtime.mod_evaluate(id);
tokio::select! {
// Not using biased mode leads to non-determinism for relatively simple
@@ -266,8 +269,7 @@ impl MainWorker {
&mut self,
module_specifier: &ModuleSpecifier,
) -> Result<(), AnyError> {
- let id = self.preload_module(module_specifier, false).await?;
- self.wait_for_inspector_session();
+ let id = self.preload_side_module(module_specifier).await?;
self.evaluate_module(id).await
}
@@ -278,8 +280,7 @@ impl MainWorker {
&mut self,
module_specifier: &ModuleSpecifier,
) -> Result<(), AnyError> {
- let id = self.preload_module(module_specifier, true).await?;
- self.wait_for_inspector_session();
+ let id = self.preload_main_module(module_specifier).await?;
self.evaluate_module(id).await
}