File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,15 +3,12 @@ import { Shrinkable } from '../arbitrary/definition/Shrinkable';
33import { IProperty } from './IProperty' ;
44
55/** @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 ( ( ) => {
109 resolve ( `Property timeout: exceeded limit of ${ timeMs } milliseconds` ) ;
11- } , timeMs ) ;
12- } ) ;
13- return { clear : ( ) => clearTimeout ( timeoutHandle ! ) , promise } ;
14- } ;
10+ } , timeMs )
11+ ) ;
1512
1613/** @hidden */
1714export class TimeoutProperty < Ts > implements IProperty < Ts > {
@@ -21,9 +18,6 @@ export class TimeoutProperty<Ts> implements IProperty<Ts> {
2118 return this . property . generate ( mrng , runId ) ;
2219 }
2320 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 ) ] ) ;
2822 }
2923}
You can’t perform that action at this time.
0 commit comments