Skip to content

Commit

Permalink
browsersynthcompiler needs to wait for moduleworkerloader
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Jan 2, 2024
1 parent c13af4e commit cf0af8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions wasmaudioworklet/synth1/browsersynthcompiler.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const synthcompilerworker = new Worker(new URL('moduleworkerloader.js', import.meta.url));
const synthcompilerworker = new Promise(resolve => {
const worker = new Worker(new URL('moduleworkerloader.js', import.meta.url));
worker.onmessage = () => resolve(worker);
});

export async function compileWebAssemblySynth(synthsource, song, samplerate, exportmode) {
synthcompilerworker.postMessage({
const worker = await synthcompilerworker;
worker.postMessage({
synthsource: synthsource,
samplerate: samplerate,
song: song,
exportmode: exportmode
});

const result = await new Promise((resolve) => synthcompilerworker.onmessage = (msg) => resolve(msg));
const result = await new Promise((resolve) => worker.onmessage = (msg) => resolve(msg));
if (result.data.binary) {
console.log('successfully compiled webassembly synth');
return result.data.binary;
Expand Down
4 changes: 2 additions & 2 deletions wasmaudioworklet/synth1/moduleworkerloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ const importMap = {
importShim.addImportMap(importMap);
importShim('./browsercompilerwebworker.js').then((res) => {
console.log("module has been loaded");
})
.catch(e => setTimeout(() => { throw e; }));
postMessage('ready');
}).catch(e => setTimeout(() => { throw e; }));
2 changes: 1 addition & 1 deletion wasmaudioworklet/web-test-runner.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { chromeLauncher } from '@web/test-runner';

export default {
concurrency: 1,
concurrency: 10,
watch: true,
testRunnerHtml: testRunnerImport =>
`<html>
Expand Down

0 comments on commit cf0af8d

Please sign in to comment.