Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postMessage support #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ keywords = ["thread", "wasm", "parallel", "concurrency"]
categories = ["concurrency", "wasm"]
readme = "README.md"

[features]
default = ["es_modules"]
es_modules = []

[dependencies]
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = [
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3.70", features = [
"Blob",
"DedicatedWorkerGlobalScope",
"MessageEvent",
Expand All @@ -38,7 +35,6 @@ log = "0.4"
env_logger = "0.10"
wasm-bindgen-test = "0.3"
async-channel = "2.2"
wasm-bindgen-futures = "0.4"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
console_log = { version = "1.0", features = ["color"] }
Expand Down
2 changes: 1 addition & 1 deletion examples-wasm-pack/web-build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

wasm-pack build --dev --out-dir ./module/target --target web --features wasm_thread/es_modules
wasm-pack build --dev --out-dir ./module/target --target web
8 changes: 0 additions & 8 deletions src/wasm32/js/module_workers_polyfill.min.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/wasm32/js/script_path.js

This file was deleted.

28 changes: 0 additions & 28 deletions src/wasm32/js/web_worker.js

This file was deleted.

35 changes: 18 additions & 17 deletions src/wasm32/js/web_worker_module.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// synchronously, using the browser, import wasm_bindgen shim JS scripts
import init, {wasm_thread_entry_point} from "WASM_BINDGEN_SHIM_URL";

// Wait for the main thread to send us the shared module/memory and work context.
// Once we've got it, initialize it all with the `wasm_bindgen` global we imported via
// `importScripts`.
self.onmessage = event => {
let [ module, memory, work ] = event.data;
let [ url, module, memory, work ] = event.data;

init(module, memory).catch(err => {
console.log(err);
(async () => {
try {
const wasm = await import(url);
wasm.initSync({ module, memory });
// Enter rust code by calling entry point defined in `lib.rs`.
// This executes closure defined by work context.
await wasm.wasm_thread_entry_point(work);
} catch (err) {
console.error(err);

// Propagate to main `onerror`:
setTimeout(() => {
// Propagate to main `onerror`:
setTimeout(() => {
throw err;
});
// Rethrow to keep promise rejected and prevent execution of further commands:
throw err;
});
// Rethrow to keep promise rejected and prevent execution of further commands:
throw err;
}).then(() => {
// Enter rust code by calling entry point defined in `lib.rs`.
// This executes closure defined by work context.
wasm_thread_entry_point(work);
}

// Once done, terminate web worker
close();
});
};
})();
};
Loading