Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
refactor(Util): remove unnecessary function
Browse files Browse the repository at this point in the history
  • Loading branch information
amishshah committed Aug 8, 2021
1 parent 86cb158 commit 219fed4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/util/abortAfter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* 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 {
export function abortAfter(delay: number): [AbortController, AbortSignal] {
const ac = new AbortController();
const timeout = setTimeout(() => ac.abort(), delay);
ac.signal.addEventListener('abort', () => clearTimeout(timeout));
return ac;
return [ac, ac.signal];
}
11 changes: 1 addition & 10 deletions src/util/entersState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function entersState<T extends VoiceConnection | AudioPlayer>(
) {
if (target.state.status !== status) {
const [ac, signal] =
timeoutOrSignal instanceof AbortSignal ? [undefined, timeoutOrSignal] : createDelayedAbort(timeoutOrSignal);
timeoutOrSignal instanceof AbortSignal ? [undefined, timeoutOrSignal] : abortAfter(timeoutOrSignal);
try {
await once(target as EventEmitter, status, { signal });
} finally {
Expand All @@ -52,12 +52,3 @@ export async function entersState<T extends VoiceConnection | AudioPlayer>(
}
return target;
}

/**
* Creates an abort controller that will abort after the specified delay.
* @param delay - The delay before aborting
*/
function createDelayedAbort(delay: number): [AbortController, AbortSignal] {
const ac = abortAfter(delay);
return [ac, ac.signal];
}

0 comments on commit 219fed4

Please sign in to comment.