File tree Expand file tree Collapse file tree 1 file changed +3
-14
lines changed Expand file tree Collapse file tree 1 file changed +3
-14
lines changed Original file line number Diff line number Diff line change 1- import { addAbortListener } from 'node:events ' ;
1+ import { setTimeout as setTimeoutAsync } from 'node:timers/promises ' ;
22
33/**
44 * Wait a set amount of milliseconds or until the timer is aborted.
@@ -7,19 +7,8 @@ import { addAbortListener } from 'node:events';
77 * @returns Promise
88 */
99export function timeout ( ms : number , abort ?: AbortController | AbortSignal ) : Promise < void > {
10- return new Promise ( ( resolve , reject ) => {
11- const signal = abort && 'signal' in abort ? abort . signal : abort ;
12- if ( signal ?. aborted ) return reject ( signal . reason ) ;
13- const disposable = signal ? addAbortListener ( signal , onAbort ) : undefined ;
14- const timeout = setTimeout ( ( ) => {
15- disposable ?. [ Symbol . dispose ?? ( Symbol . for ( 'nodejs.dispose' ) as typeof Symbol . dispose ) ] ( ) ;
16- resolve ( ) ;
17- } , ms ) ;
18- function onAbort ( ) {
19- clearTimeout ( timeout ) ;
20- reject ( signal ?. reason ) ;
21- }
22- } ) ;
10+ const signal = abort && ( abort instanceof AbortSignal ? abort : abort . signal ) ;
11+ return setTimeoutAsync ( ms , undefined , { signal } ) ;
2312}
2413
2514/**
You can’t perform that action at this time.
0 commit comments