File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,12 @@ import { Shrinkable } from '../arbitrary/definition/Shrinkable';
3
3
import { IProperty } from './IProperty' ;
4
4
5
5
/** @hidden */
6
- const timeoutAfter = ( timeMs : number ) => {
7
- let timeoutHandle : ( ReturnType < typeof setTimeout > ) | null = null ;
8
- const promise = new Promise < string > ( ( resolve , reject ) => {
9
- timeoutHandle = setTimeout ( ( ) => {
6
+ const timeoutAfter = async ( timeMs : number ) =>
7
+ new Promise < string > ( ( resolve , reject ) =>
8
+ setTimeout ( ( ) => {
10
9
resolve ( `Property timeout: exceeded limit of ${ timeMs } milliseconds` ) ;
11
- } , timeMs ) ;
12
- } ) ;
13
- return { clear : ( ) => clearTimeout ( timeoutHandle ! ) , promise } ;
14
- } ;
10
+ } , timeMs )
11
+ ) ;
15
12
16
13
/** @hidden */
17
14
export class TimeoutProperty < Ts > implements IProperty < Ts > {
@@ -21,9 +18,6 @@ export class TimeoutProperty<Ts> implements IProperty<Ts> {
21
18
return this . property . generate ( mrng , runId ) ;
22
19
}
23
20
async run ( v : Ts ) {
24
- const t = timeoutAfter ( this . timeMs ) ;
25
- const propRun = Promise . race ( [ this . property . run ( v ) , t . promise ] ) ;
26
- propRun . then ( t . clear , t . clear ) ; // always clear timeout handle (equivalent to finally)
27
- return propRun ;
21
+ return Promise . race ( [ this . property . run ( v ) , timeoutAfter ( this . timeMs ) ] ) ;
28
22
}
29
23
}
You can’t perform that action at this time.
0 commit comments