Skip to content

Commit

Permalink
Merge pull request #15 from erwanvivien/adding-api
Browse files Browse the repository at this point in the history
feat: added an api to pass self-built worker shim
  • Loading branch information
chemicstry authored Mar 17, 2024
2 parents 2ea79c4 + 3b97535 commit 38d76f2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/wasm32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub struct Builder {
name: Option<String>,
// A prefix for the thread-to-be, for identification in panic messages
prefix: Option<String>,
// The URL of the web worker script to use as web worker thread script
worker_script_url: Option<String>,
// The size of the stack for the spawned thread in bytes
stack_size: Option<usize>,
// Url of the `wasm_bindgen` generated shim `.js` script to use as web worker entry point
Expand All @@ -98,6 +100,7 @@ impl Builder {
Self {
name: None,
prefix: None,
worker_script_url: None,
stack_size: None,
wasm_bindgen_shim_url: None,
}
Expand All @@ -114,6 +117,11 @@ impl Builder {
self
}

pub fn worker_script_url(mut self, worker_script_url: String) -> Builder {
self.worker_script_url = Some(worker_script_url);
self
}

/// Sets the name of the thread.
///
/// If not set, the default name is autogenerated.
Expand Down Expand Up @@ -263,12 +271,13 @@ impl Builder {
let Builder {
name,
prefix,
worker_script_url,
wasm_bindgen_shim_url,
..
} = self;

// Get worker script as URL encoded blob
let script = get_worker_script(wasm_bindgen_shim_url);
let script = worker_script_url.unwrap_or(get_worker_script(wasm_bindgen_shim_url));

// Todo: figure out how to set stack size
let mut options = WorkerOptions::new();
Expand Down

0 comments on commit 38d76f2

Please sign in to comment.