diff --git a/src/mono/wasm/runtime/pthreads/browser/index.ts b/src/mono/wasm/runtime/pthreads/browser/index.ts index 021bc6c70a666d..b7c62e9599303c 100644 --- a/src/mono/wasm/runtime/pthreads/browser/index.ts +++ b/src/mono/wasm/runtime/pthreads/browser/index.ts @@ -135,12 +135,14 @@ export function preAllocatePThreadWorkerPool(defaultPthreadPoolSize: number, con export async function instantiateWasmPThreadWorkerPool(): Promise { // this is largely copied from emscripten's "receiveInstance" in "createWasm" in "src/preamble.js" const workers = Internals.getUnusedWorkerPool(); - const allLoaded = createPromiseController(); - let leftToLoad = workers.length; - workers.forEach((w) => { - Internals.loadWasmModuleToWorker(w, function () { - if (!--leftToLoad) allLoaded.promise_control.resolve(); + if (workers.length > 0) { + const allLoaded = createPromiseController(); + let leftToLoad = workers.length; + workers.forEach((w) => { + Internals.loadWasmModuleToWorker(w, function () { + if (!--leftToLoad) allLoaded.promise_control.resolve(); + }); }); - }); - await allLoaded.promise; + await allLoaded.promise; + } }