parent
521800b42e
commit
a153fa466f
@ -0,0 +1,38 @@
|
||||
import { TIMER_EVENT_CANCELLED, TIMER_STATUS_CANCELLED } from './consts.ts';
|
||||
import {
|
||||
isTimerKeyInScope,
|
||||
timerEntrySnapshot,
|
||||
type InternalTimerEntry
|
||||
} from './timer-entry.ts';
|
||||
import type { TimerClock, TimerEvent } from './types.ts';
|
||||
|
||||
export interface CancelTimerEntryInput {
|
||||
readonly entry: InternalTimerEntry;
|
||||
readonly entries: Map<string, InternalTimerEntry>;
|
||||
readonly clock: TimerClock;
|
||||
emit(event: TimerEvent): void;
|
||||
}
|
||||
|
||||
export function cancelTimerEntry(input: CancelTimerEntryInput): void {
|
||||
const { entry, entries, clock } = input;
|
||||
entry.version += 1;
|
||||
entry.status = TIMER_STATUS_CANCELLED;
|
||||
if (entry.native !== null) {
|
||||
clock.clearTimeout(entry.native);
|
||||
entry.native = null;
|
||||
}
|
||||
entry.controller.abort();
|
||||
entries.delete(entry.key);
|
||||
input.emit({ type: TIMER_EVENT_CANCELLED, entry: timerEntrySnapshot(entry) });
|
||||
}
|
||||
|
||||
export function collectTimerKeysInScope(
|
||||
entries: Map<string, InternalTimerEntry>,
|
||||
scope: string | undefined
|
||||
): string[] {
|
||||
const keys: string[] = [];
|
||||
for (const key of entries.keys()) {
|
||||
if (scope === undefined || isTimerKeyInScope(key, scope)) keys.push(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
Loading…
Reference in new issue