@@ -86,25 +86,46 @@ public suspend fun SearchClient.waitForApiKey(
8686 * @param maxRetries maximum number of retry attempts.
8787 * @param requestOptions additional request configuration.
8888 */
89- public suspend fun SearchClient.waitTask (
89+ public suspend fun SearchClient.waitForTask (
9090 indexName : String ,
9191 taskID : Long ,
9292 maxRetries : Int = 50,
9393 timeout : Duration = Duration .INFINITE ,
9494 initialDelay : Duration = 200.milliseconds,
9595 maxDelay : Duration = 5.seconds,
9696 requestOptions : RequestOptions ? = null,
97- ): TaskStatus {
97+ ): GetTaskResponse {
9898 return retryUntil(
9999 timeout = timeout,
100100 maxRetries = maxRetries,
101101 initialDelay = initialDelay,
102102 maxDelay = maxDelay,
103- retry = { getTask(indexName, taskID, requestOptions).status },
104- until = { it == TaskStatus .Published },
103+ retry = { getTask(indexName, taskID, requestOptions) },
104+ until = { it.status == TaskStatus .Published },
105105 )
106106}
107107
108+ @Deprecated(" Please use waitForTask instead" , ReplaceWith (" waitForTask(indexName, taskID, maxRetries, timeout, initialDelay, maxDelay, requestOptions)" ))
109+ public suspend fun SearchClient.waitTask (
110+ indexName : String ,
111+ taskID : Long ,
112+ maxRetries : Int = 50,
113+ timeout : Duration = Duration .INFINITE ,
114+ initialDelay : Duration = 200.milliseconds,
115+ maxDelay : Duration = 5.seconds,
116+ requestOptions : RequestOptions ? = null,
117+ ): TaskStatus {
118+ return waitForTask(
119+ indexName = indexName,
120+ taskID = taskID,
121+ maxRetries = maxRetries,
122+ timeout = timeout,
123+ initialDelay = initialDelay,
124+ maxDelay = maxDelay,
125+ requestOptions = requestOptions,
126+ ).status
127+ }
128+
108129/* *
109130 * Wait for an application-level [taskID] to complete before executing the next line of code.
110131 *
@@ -115,24 +136,43 @@ public suspend fun SearchClient.waitTask(
115136 * @param maxRetries maximum number of retry attempts.
116137 * @param requestOptions additional request configuration.
117138 */
118- public suspend fun SearchClient.waitAppTask (
139+ public suspend fun SearchClient.waitForAppTask (
119140 taskID : Long ,
120141 maxRetries : Int = 50,
121142 timeout : Duration = Duration .INFINITE ,
122143 initialDelay : Duration = 200.milliseconds,
123144 maxDelay : Duration = 5.seconds,
124145 requestOptions : RequestOptions ? = null,
125- ): TaskStatus {
146+ ): GetTaskResponse {
126147 return retryUntil(
127148 timeout = timeout,
128149 maxRetries = maxRetries,
129150 initialDelay = initialDelay,
130151 maxDelay = maxDelay,
131- retry = { getAppTask(taskID, requestOptions).status },
132- until = { it == TaskStatus .Published },
152+ retry = { getAppTask(taskID, requestOptions) },
153+ until = { it.status == TaskStatus .Published },
133154 )
134155}
135156
157+ @Deprecated(" Please use waitForAppTask instead" , ReplaceWith (" waitForAppTask(taskID, maxRetries, timeout, initialDelay, maxDelay, requestOptions)" ))
158+ public suspend fun SearchClient.waitAppTask (
159+ taskID : Long ,
160+ maxRetries : Int = 50,
161+ timeout : Duration = Duration .INFINITE ,
162+ initialDelay : Duration = 200.milliseconds,
163+ maxDelay : Duration = 5.seconds,
164+ requestOptions : RequestOptions ? = null,
165+ ): TaskStatus {
166+ return waitForAppTask(
167+ taskID = taskID,
168+ maxRetries = maxRetries,
169+ timeout = timeout,
170+ initialDelay = initialDelay,
171+ maxDelay = maxDelay,
172+ requestOptions = requestOptions,
173+ ).status
174+ }
175+
136176/* *
137177 * Wait on an API key update operation.
138178 *
@@ -312,7 +352,7 @@ public suspend fun SearchClient.chunkedBatch(
312352 tasks.add(batch)
313353 }
314354 if (waitForTask) {
315- tasks.forEach { waitTask (indexName, it.taskID) }
355+ tasks.forEach { waitForTask (indexName, it.taskID) }
316356 }
317357 return tasks
318358}
@@ -431,7 +471,7 @@ public suspend fun SearchClient.replaceAllObjects(
431471 requestOptions = requestOptions,
432472 )
433473
434- waitTask (indexName = tmpIndexName, taskID = copy.taskID)
474+ waitForTask (indexName = tmpIndexName, taskID = copy.taskID)
435475
436476 copy = operationIndex(
437477 indexName = indexName,
@@ -442,14 +482,14 @@ public suspend fun SearchClient.replaceAllObjects(
442482 ),
443483 requestOptions = requestOptions,
444484 )
445- waitTask (indexName = tmpIndexName, taskID = copy.taskID)
485+ waitForTask (indexName = tmpIndexName, taskID = copy.taskID)
446486
447487 val move = operationIndex(
448488 indexName = tmpIndexName,
449489 operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
450490 requestOptions = requestOptions,
451491 )
452- waitTask (indexName = tmpIndexName, taskID = move.taskID)
492+ waitForTask (indexName = tmpIndexName, taskID = move.taskID)
453493
454494 return ReplaceAllObjectsResponse (copy, batchResponses, move)
455495}
0 commit comments