Commit 954e7ea 1 parent be9721b commit 954e7ea Copy full SHA for 954e7ea
File tree 1 file changed +3
-14
lines changed
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 ' ;
2
2
3
3
/**
4
4
* Wait a set amount of milliseconds or until the timer is aborted.
@@ -7,19 +7,8 @@ import { addAbortListener } from 'node:events';
7
7
* @returns Promise
8
8
*/
9
9
export 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 } ) ;
23
12
}
24
13
25
14
/**
You can’t perform that action at this time.
0 commit comments