Skip to content

Commit

Permalink
Convert loadWasmModuleToAllWorkers to async/await. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Dec 19, 2024
1 parent aead0b0 commit 9f4dbf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ var LibraryPThread = {
#if !MINIMAL_RUNTIME
// MINIMAL_RUNTIME takes care of calling loadWasmModuleToAllWorkers
// in postamble_minimal.js
addOnPreRun(() => {
addOnPreRun(async () => {
addRunDependency('loading-workers')
PThread.loadWasmModuleToAllWorkers(() => removeRunDependency('loading-workers'));
await PThread.loadWasmModuleToAllWorkers();
removeRunDependency('loading-workers');
});
#endif
#if MAIN_MODULE
Expand Down Expand Up @@ -362,9 +363,9 @@ var LibraryPThread = {
});
}),

loadWasmModuleToAllWorkers(onMaybeReady) {
async loadWasmModuleToAllWorkers() {
#if !PTHREAD_POOL_SIZE
onMaybeReady();
return;
#else
// Instantiation is synchronous in pthreads.
if (
Expand All @@ -373,7 +374,7 @@ var LibraryPThread = {
|| ENVIRONMENT_IS_WASM_WORKER
#endif
) {
return onMaybeReady();
return;
}

let pthreadPoolReady = Promise.all(PThread.unusedWorkers.map(PThread.loadWasmModuleToWorker));
Expand All @@ -383,9 +384,9 @@ var LibraryPThread = {
// If the user wants to wait on it elsewhere, they can do so via the
// Module['pthreadPoolReady'] promise.
Module['pthreadPoolReady'] = pthreadPoolReady;
onMaybeReady();
return;
#else
pthreadPoolReady.then(onMaybeReady);
await pthreadPoolReady;
#endif // PTHREAD_POOL_DELAY_LOAD
#endif // PTHREAD_POOL_SIZE
},
Expand Down
2 changes: 1 addition & 1 deletion src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
#if PTHREADS
// Export Wasm module for pthread creation to access.
wasmModule = output.module || Module['wasm'];
PThread.loadWasmModuleToAllWorkers(ready);
PThread.loadWasmModuleToAllWorkers().then(ready);
#else
ready();
#endif
Expand Down

0 comments on commit 9f4dbf4

Please sign in to comment.