Make errors in the disk and audio workers not block the emulator

Before, if there was an error in the audio worker or in the disk
worker, the emulator would not start. This could happen, for example,
if the page is loaded directly from disk in Chrome instead of through
a server.

Now, even if there is an error, the emulator will start.
This commit is contained in:
Ian Flanigan 2022-08-21 11:47:38 +02:00
parent 89cf6aa17b
commit 079767642f
No known key found for this signature in database
GPG Key ID: 035F657DAE4AE7EC
2 changed files with 23 additions and 19 deletions

View File

@ -942,25 +942,29 @@ export default class DiskII implements Card<State>, MassStorage<NibbleFormat> {
return;
}
this.worker = new Worker('dist/format_worker.bundle.js');
try {
this.worker = new Worker('dist/format_worker.bundle.js');
this.worker.addEventListener('message', (message: MessageEvent<FormatWorkerResponse>) => {
const { data } = message;
switch (data.type) {
case DISK_PROCESSED:
{
const { drive, disk } = data.payload;
if (disk) {
const cur = this.drives[drive - 1];
Object.assign(cur, disk);
const { name, side } = cur;
this.updateDirty(drive, true);
this.callbacks.label(drive, name, side);
this.worker.addEventListener('message', (message: MessageEvent<FormatWorkerResponse>) => {
const { data } = message;
switch (data.type) {
case DISK_PROCESSED:
{
const { drive, disk } = data.payload;
if (disk) {
const cur = this.drives[drive - 1];
Object.assign(cur, disk);
const { name, side } = cur;
this.updateDirty(drive, true);
this.callbacks.label(drive, name, side);
}
}
}
break;
}
});
break;
}
});
} catch (e: unknown) {
console.error(e);
}
}
// TODO(flan): Does not work with WOZ or D13 disks

View File

@ -37,8 +37,8 @@ export class Audio implements OptionHandler {
});
if (window.AudioWorklet) {
this.ready = this.audioContext.audioWorklet.addModule('./dist/audio_worker.bundle.js');
this.ready
const workletReady = this.audioContext.audioWorklet.addModule('./dist/audio_worker.bundle.js');
this.ready = workletReady
.then(() => {
this.workletNode = new AudioWorkletNode(this.audioContext, 'audio_worker');