mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
14 lines
486 B
TypeScript
14 lines
486 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
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
ac.signal.addEventListener('abort', () => clearTimeout(timeout));
|
|
return [ac, ac.signal];
|
|
}
|