Skip to content

Convert loadWasmModuleToAllWorkers to async/await. NFC #23232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading