File tree Expand file tree Collapse file tree 2 files changed +16
-13
lines changed
clients/algoliasearch-client-javascript/packages/client-common/src Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -20,22 +20,25 @@ export function createIterablePromise<TResponse>({
20
20
const retry = ( previousResponse ?: TResponse ) : Promise < TResponse > => {
21
21
return new Promise < TResponse > ( ( resolve , reject ) => {
22
22
func ( previousResponse )
23
- . then ( ( response ) => {
23
+ . then ( async ( response ) => {
24
24
if ( aggregator ) {
25
- aggregator ( response ) ;
25
+ await aggregator ( response ) ;
26
26
}
27
27
28
- if ( validate ( response ) ) {
28
+ if ( await validate ( response ) ) {
29
29
return resolve ( response ) ;
30
30
}
31
31
32
- if ( error && error . validate ( response ) ) {
33
- return reject ( new Error ( error . message ( response ) ) ) ;
32
+ if ( error && ( await error . validate ( response ) ) ) {
33
+ return reject ( new Error ( await error . message ( response ) ) ) ;
34
34
}
35
35
36
- return setTimeout ( ( ) => {
37
- retry ( response ) . then ( resolve ) . catch ( reject ) ;
38
- } , timeout ( ) ) ;
36
+ return setTimeout (
37
+ ( ) => {
38
+ retry ( response ) . then ( resolve ) . catch ( reject ) ;
39
+ } ,
40
+ await timeout ( ) ,
41
+ ) ;
39
42
} )
40
43
. catch ( ( err ) => {
41
44
reject ( err ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ export type IterableOptions<TResponse> = Partial<{
2
2
/**
3
3
* The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
4
4
*/
5
- aggregator : ( response : TResponse ) => void ;
5
+ aggregator : ( response : TResponse ) => unknown | PromiseLike < unknown > ;
6
6
7
7
/**
8
8
* The `validate` condition to throw an error and its message.
@@ -11,18 +11,18 @@ export type IterableOptions<TResponse> = Partial<{
11
11
/**
12
12
* The function to validate the error condition.
13
13
*/
14
- validate : ( response : TResponse ) => boolean ;
14
+ validate : ( response : TResponse ) => boolean | PromiseLike < boolean > ;
15
15
16
16
/**
17
17
* The error message to throw.
18
18
*/
19
- message : ( response : TResponse ) => string ;
19
+ message : ( response : TResponse ) => string | PromiseLike < string > ;
20
20
} ;
21
21
22
22
/**
23
23
* The function to decide how long to wait between iterations.
24
24
*/
25
- timeout : ( ) => number ;
25
+ timeout : ( ) => number | PromiseLike < number > ;
26
26
} > ;
27
27
28
28
export type CreateIterablePromise < TResponse > = IterableOptions < TResponse > & {
@@ -36,5 +36,5 @@ export type CreateIterablePromise<TResponse> = IterableOptions<TResponse> & {
36
36
/**
37
37
* The validator function. It receive the resolved return of the API call.
38
38
*/
39
- validate : ( response : TResponse ) => boolean ;
39
+ validate : ( response : TResponse ) => boolean | PromiseLike < boolean > ;
40
40
} ;
You can’t perform that action at this time.
0 commit comments