Skip to main content

Wait for a task to finish

The waitForTask method is only available in the search client context.

Some operations related to the Algolia index are not always instantaneous. Doing such operations with our API clients will provide a taskID in the response body, so you can later know what is the status of your operation.

We provide a waitForTask helper method for you to easily wait for a specific task status.

java
import com.algolia.model.search.*;
Map<String, Object> body = new HashMap<>();
body.put("title", "My Algolia Object");
SaveObjectResponse response = client.saveObject(
"<YOUR_INDEX_NAME>",
body
);
// Poll the task status with defaults values
await client.waitForTask("<YOUR_INDEX_NAME>", response.getTaskID());
// Poll the task status with your options
client.waitForTask(
"<YOUR_INDEX_NAME>",
response.getTaskID(),
// Number of maximum retries to do
100,
// The time to wait between tries
retryCount -> {
return Math.min(retryCount * 200, 5000);
}
);
java
import com.algolia.model.search.*;
Map<String, Object> body = new HashMap<>();
body.put("title", "My Algolia Object");
SaveObjectResponse response = client.saveObject(
"<YOUR_INDEX_NAME>",
body
);
// Poll the task status with defaults values
await client.waitForTask("<YOUR_INDEX_NAME>", response.getTaskID());
// Poll the task status with your options
client.waitForTask(
"<YOUR_INDEX_NAME>",
response.getTaskID(),
// Number of maximum retries to do
100,
// The time to wait between tries
retryCount -> {
return Math.min(retryCount * 200, 5000);
}
);