File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
1
/* @flow strict-local */
2
2
import { isClientError } from '../api/apiErrors' ;
3
3
4
+ /** Like setTimeout(..., 0), but returns a Promise of the result. */
5
+ export function delay < T > ( callback : ( ) = > T ) : Promise < T > {
6
+ return new Promise ( resolve => resolve ( ) ) . then ( callback ) ;
7
+ }
8
+
9
+ export const sleep = ( ms : number = 0 ) : Promise < void > =>
10
+ new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
11
+
4
12
/**
5
13
* Makes a machine that can sleep for a timeout that, until a ceiling is reached,
6
14
* grows exponentially in duration with the number of sleeps completed, with a
@@ -47,21 +55,13 @@ export const makeBackoffMachine = () => {
47
55
firstDuration * base ** numSleepsCompleted ,
48
56
) ;
49
57
50
- await new Promise ( resolve => setTimeout ( resolve , duration ) ) ;
58
+ await sleep ( duration ) ;
51
59
52
60
numSleepsCompleted ++ ;
53
61
} ,
54
62
} ;
55
63
} ;
56
64
57
- /** Like setTimeout(..., 0), but returns a Promise of the result. */
58
- export function delay < T > ( callback : ( ) = > T ) : Promise < T > {
59
- return new Promise ( resolve => resolve ( ) ) . then ( callback ) ;
60
- }
61
-
62
- export const sleep = ( ms : number = 0 ) : Promise < void > =>
63
- new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
64
-
65
65
/**
66
66
* Calls an async function and if unsuccessful retries the call.
67
67
*
You can’t perform that action at this time.
0 commit comments