Files
discord.js/packages/voice/src/util/abortAfter.ts
2022-09-01 21:26:09 +02:00

13 lines
444 B
TypeScript

/**
* Creates an abort controller that aborts after the given time.
*
* @param delay - The time in milliseconds to wait before aborting
*/
export function abortAfter(delay: number): [AbortController, AbortSignal] {
const ac = new AbortController();
const timeout = setTimeout(() => ac.abort(), delay);
// @ts-expect-error: No type for timeout
ac.signal.addEventListener('abort', () => clearTimeout(timeout));
return [ac, ac.signal];
}