Skip to content

Commit a25ee40

Browse files
committed
fix: bind scheduler timer defaults
1 parent 8b7b7ac commit a25ee40

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/audio/lookahead-scheduler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ export interface LookaheadSchedulerOptions<TEvent extends TickEvent> {
5959
const DEFAULT_LOOKAHEAD_MS = 25;
6060
const DEFAULT_SCHEDULE_AHEAD_TIME = 0.1;
6161

62-
type SchedulerTimerId = ReturnType<typeof setInterval>;
62+
type SchedulerTimerId = ReturnType<typeof globalThis.setInterval>;
6363
type SetSchedulerInterval = (
6464
handler: () => void,
6565
timeoutMs: number,
6666
) => SchedulerTimerId;
6767
type ClearSchedulerInterval = (timerId: SchedulerTimerId) => void;
6868

69+
const defaultSetSchedulerInterval: SetSchedulerInterval = (handler, timeoutMs) =>
70+
globalThis.setInterval(handler, timeoutMs);
71+
const defaultClearSchedulerInterval: ClearSchedulerInterval = (timerId) =>
72+
globalThis.clearInterval(timerId);
73+
6974
export function collectScheduledEventsForWindow<TEvent extends TickEvent>({
7075
audioStartTime,
7176
events,
@@ -170,7 +175,7 @@ export class LookaheadScheduler<TEvent extends TickEvent> {
170175
readonly tempoBpm: number;
171176

172177
constructor({
173-
clearIntervalFn = clearInterval,
178+
clearIntervalFn = defaultClearSchedulerInterval,
174179
events,
175180
getAudioTime,
176181
lookaheadMs = DEFAULT_LOOKAHEAD_MS,
@@ -179,7 +184,7 @@ export class LookaheadScheduler<TEvent extends TickEvent> {
179184
ppq = DEFAULT_PPQ,
180185
scheduleAheadTime = DEFAULT_SCHEDULE_AHEAD_TIME,
181186
scheduleEvent,
182-
setIntervalFn = setInterval,
187+
setIntervalFn = defaultSetSchedulerInterval,
183188
tempoBpm,
184189
}: LookaheadSchedulerOptions<TEvent>) {
185190
validateLoopRange(loopStartTick, loopEndTick);

0 commit comments

Comments
 (0)