3
3
createTransporter ,
4
4
getAlgoliaAgent ,
5
5
shuffle ,
6
+ createRetryablePromise ,
6
7
} from '@experimental-api-clients-automation/client-common' ;
7
8
import type {
8
9
CreateClientOptions ,
@@ -11,6 +12,7 @@ import type {
11
12
Request ,
12
13
RequestOptions ,
13
14
QueryParameters ,
15
+ CreateRetryablePromiseOptions ,
14
16
} from '@experimental-api-clients-automation/client-common' ;
15
17
16
18
import type { AddApiKeyResponse } from '../model/addApiKeyResponse' ;
@@ -138,6 +140,35 @@ export function createSearchClient(options: CreateClientOptions) {
138
140
139
141
return {
140
142
addAlgoliaAgent,
143
+ /**
144
+ * Wait for a task to complete with `indexName` and `taskID`.
145
+ *
146
+ * @summary Wait for a task to complete.
147
+ * @param waitForTaskProps - The waitForTaskProps object.
148
+ * @param waitForTaskProps.indexName - The index in which to perform the request.
149
+ * @param waitForTaskProps.taskID - The unique identifier of the task to wait for.
150
+ */
151
+ waitForTask ( {
152
+ indexName,
153
+ taskID,
154
+ ...createRetryablePromiseOptions
155
+ } : Omit <
156
+ CreateRetryablePromiseOptions < GetTaskResponse > ,
157
+ 'func' | 'validate'
158
+ > & {
159
+ indexName : string ;
160
+ taskID : number ;
161
+ } ) : Promise < void > {
162
+ return new Promise < void > ( ( resolve , reject ) => {
163
+ createRetryablePromise < GetTaskResponse > ( {
164
+ ...createRetryablePromiseOptions ,
165
+ func : ( ) => this . getTask ( { indexName, taskID } ) ,
166
+ validate : ( response ) => response . status === 'published' ,
167
+ } )
168
+ . then ( ( ) => resolve ( ) )
169
+ . catch ( reject ) ;
170
+ } ) ;
171
+ } ,
141
172
/**
142
173
* Add a new API Key with specific permissions/restrictions.
143
174
*
0 commit comments