scheduler error callback

This commit is contained in:
Felix Roos 2022-08-17 23:55:06 +02:00
parent 591855919e
commit e77129fa51

View file

@ -11,8 +11,9 @@ export class Scheduler {
pattern; pattern;
phase; phase;
cps = 1; cps = 1;
constructor({ interval = 0.1, onTrigger, latency = 0.1 }) { constructor({ interval = 0.1, onTrigger, onError, latency = 0.1 }) {
this.worker = new ClockWorker((_, interval) => { this.worker = new ClockWorker((_, interval) => {
try {
const begin = this.phase; const begin = this.phase;
const end = this.phase + interval * this.cps; const end = this.phase + interval * this.cps;
this.phase = end; this.phase = end;
@ -29,6 +30,10 @@ export class Scheduler {
const duration = hap.duration / this.cps; const duration = hap.duration / this.cps;
onTrigger?.(hap, deadline, duration); onTrigger?.(hap, deadline, duration);
}); });
} catch (err) {
console.warn('scheduler error', err);
onError?.(err);
}
}, interval); }, interval);
} }
start() { start() {