File tree 1 file changed +10
-2
lines changed 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -32,15 +32,23 @@ assert(buffer instanceof SharedArrayBuffer);
32
32
// stopped when we exit.
33
33
const worker = new Worker ( `
34
34
const { parentPort } = require('worker_threads');
35
+
36
+ // Compile the same WASM module from its source bytes.
35
37
const wasmSource = new Uint8Array([${ wasmSource . join ( ',' ) } ]);
36
38
const wasmModule = new WebAssembly.Module(wasmSource);
37
39
const instance = new WebAssembly.Instance(wasmModule);
38
40
parentPort.postMessage(instance.exports.memory);
41
+
42
+ // Do the same thing, except we receive the WASM module via transfer.
43
+ parentPort.once('message', ({ wasmModule }) => {
44
+ const instance = new WebAssembly.Instance(wasmModule);
45
+ parentPort.postMessage(instance.exports.memory);
46
+ });
39
47
` , { eval : true } ) ;
40
- worker . once ( 'message' , common . mustCall ( ( { buffer } ) => {
48
+ worker . on ( 'message' , common . mustCall ( ( { buffer } ) => {
41
49
assert ( buffer instanceof SharedArrayBuffer ) ;
42
50
worker . buf = buffer ; // Basically just keep the reference to buffer alive.
43
- } ) ) ;
51
+ } , 2 ) ) ;
44
52
worker . once ( 'exit' , common . mustCall ( ) ) ;
45
53
worker . postMessage ( { wasmModule } ) ;
46
54
}
You can’t perform that action at this time.
0 commit comments