1
+ #! /bin/bash
2
+
3
+ # Create the directory if it doesn't exist
4
+ mkdir -p packages/webz-wallet/snippets/wasm_thread-8ee53d0673203880/src/wasm32/js
5
+
6
+ # Create the worker module file
7
+ cat > packages/webz-wallet/snippets/wasm_thread-8ee53d0673203880/src/wasm32/js/web_worker_module.bundler.js << 'EOL '
8
+ // synchronously, using the browser, import wasm_bindgen shim JS scripts
9
+ import init, { wasm_thread_entry_point } from "../../../../../";
10
+ // Wait for the main thread to send us the shared module/memory and work context.
11
+ // Once we've got it, initialize it all with the `wasm_bindgen` global we imported via
12
+ // `importScripts`.
13
+ self.onmessage = event => {
14
+ let [ module, memory, work, thread_key ] = event.data;
15
+ init(module, memory).catch(err => {
16
+ console.log(err);
17
+ const error = new Error(err.message);
18
+ error.customProperty = "This error right here!";
19
+ // Propagate to main `onerror`:
20
+ setTimeout(() => {
21
+ throw error;
22
+ });
23
+ // Rethrow to keep promise rejected and prevent execution of further commands:
24
+ throw error;
25
+ }).then(() => {
26
+ // Enter rust code by calling entry point defined in `lib.rs`.
27
+ // This executes closure defined by work context.
28
+ wasm_thread_entry_point(work);
29
+ });
30
+ };
31
+ self.onunhandledrejection = function(e) {
32
+ console.error('Worker unhandled rejection:', e.reason);
33
+ throw e.reason;
34
+ };
35
+ self.onerror = function(e) {
36
+ console.error('Worker error:', e.message);
37
+ throw e;
38
+ };
39
+
40
+ self.onended = function(e) {
41
+ console.error('Worker ended:', e.message);
42
+ throw e;
43
+ }
44
+ EOL
0 commit comments