@@ -27,12 +27,14 @@ function waitForMsgType(target, type) {
2727// We need to wait for a specific message because this file is used both
2828// as a Worker and as a regular script, so it might receive unrelated
2929// messages on the page.
30- waitForMsgType ( self , 'wasm_bindgen_worker_init' ) . then ( async data => {
31- const pkg = await import ( data . mainJS ) ;
32- await pkg . initSync ( data . init ) ;
33- postMessage ( { type : 'wasm_bindgen_worker_ready' } ) ;
34- pkg . wbg_rayon_start_worker ( data . receiver ) ;
35- } ) ;
30+ if ( name === "wasm_bindgen_worker" ) {
31+ waitForMsgType ( self , 'wasm_bindgen_worker_init' ) . then ( async data => {
32+ const pkg = await import ( data . mainJS ) ;
33+ await pkg . initSync ( data . init ) ;
34+ postMessage ( { type : 'wasm_bindgen_worker_ready' } ) ;
35+ pkg . wbg_rayon_start_worker ( data . receiver ) ;
36+ } ) ;
37+ }
3638
3739export async function startWorkers ( module , memory , builder ) {
3840 const workerInit = {
@@ -51,7 +53,8 @@ export async function startWorkers(module, memory, builder) {
5153 let scriptBlob = await fetch ( import . meta. url ) . then ( r => r . blob ( ) ) ;
5254 let url = URL . createObjectURL ( scriptBlob ) ;
5355 const worker = new Worker ( url , {
54- type : 'module'
56+ type : 'module' ,
57+ name : 'wasm_bindgen_worker'
5558 } ) ;
5659 worker . postMessage ( workerInit ) ;
5760 await waitForMsgType ( worker , 'wasm_bindgen_worker_ready' ) ;
0 commit comments