Skip to content

Commit 7c3be8e

Browse files
authored
Extract a worker var in allocateUnusedWorker. NFC (#18304)
1 parent 50d143d commit 7c3be8e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/library_pthread.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ var LibraryPThread = {
404404

405405
// Creates a new web Worker and places it in the unused worker pool to wait for its use.
406406
allocateUnusedWorker: function() {
407+
var worker;
407408
#if MINIMAL_RUNTIME
408409
var pthreadMainJs = Module['worker'];
409410
#else
@@ -424,12 +425,11 @@ var LibraryPThread = {
424425
}
425426
}
426427
);
427-
PThread.unusedWorkers.push(new Worker(p.createScriptURL('ignored')));
428+
worker = new Worker(p.createScriptURL('ignored'));
428429
} else
429430
#endif
430-
PThread.unusedWorkers.push(new Worker(new URL('{{{ PTHREAD_WORKER_FILE }}}', import.meta.url)));
431-
return;
432-
}
431+
worker = new Worker(new URL('{{{ PTHREAD_WORKER_FILE }}}', import.meta.url));
432+
} else {
433433
#endif
434434
// Allow HTML module to configure the location where the 'worker.js' file will be loaded from,
435435
// via Module.locateFile() function. If not specified, then the default URL 'worker.js' relative
@@ -443,10 +443,14 @@ var LibraryPThread = {
443443
// Use Trusted Types compatible wrappers.
444444
if (typeof trustedTypes != 'undefined' && trustedTypes.createPolicy) {
445445
var p = trustedTypes.createPolicy('emscripten#workerPolicy2', { createScriptURL: function(ignored) { return pthreadMainJs } });
446-
PThread.unusedWorkers.push(new Worker(p.createScriptURL('ignored')));
446+
worker = new Worker(p.createScriptURL('ignored'));
447447
} else
448448
#endif
449-
PThread.unusedWorkers.push(new Worker(pthreadMainJs));
449+
worker = new Worker(pthreadMainJs);
450+
#if EXPORT_ES6 && USE_ES6_IMPORT_META
451+
}
452+
#endif
453+
PThread.unusedWorkers.push(worker);
450454
},
451455

452456
getNewWorker: function() {

0 commit comments

Comments
 (0)