API Reference / API Methods / Advanced / Wait for operations
Feb. 26, 2019

Wait For Operations

Required API Key: any key with the addObject ACL
Method signature
$index->saveObject(...)->wait();
$index->saveObjects(...)->wait();
$index->partialUpdateObject(...)->wait();
$index->partialUpdateObjects(...)->wait();
$index->replaceAllObjects(...)->wait();
$index->deleteObject(...)->wait();
$index->deleteObjects(...)->wait();
$index->deleteBy(...)->wait();
$index->clearObjects(...)->wait();
$index->batch(...)->wait();

$index->setSettings(...)->wait();

$index->saveSynonym(...)->wait();
$index->saveSynonyms(...)->wait();
$index->replaceAllSynonyms(...)->wait();
$index->deleteSynonym(...)->wait();
$index->clearSynonyms(...)->wait();

$index->saveRule(...)->wait();
$index->saveRules(...)->wait();
$index->replaceAllRules(...)->wait();
$index->deleteRule(...)->wait();
$index->clearRules(...)->wait();


$client->moveIndex(...)->wait();
$client->copyIndex(...)->wait();
$client->copyRules(...)->wait();
$client->copySynonyms(...)->wait();
$client->copySettings(...)->wait();

$client->addApiKey(...)->wait();
$client->updateApiKey(...)->wait();
$client->deleteApiKey(...)->wait();
$client->multipleBatch(...)->wait();

About this method

Wait for a task to complete before executing the next line of code, to synchronize index updates.

All write operations in Algolia are asynchronous by design.

It means that when you add or update an object to your index, our servers will reply to your request with a taskID as soon as they understood the write operation. The actual insert and indexing will be done after replying to your code. You can wait for a task to complete by using the `taskID’ and this method.

Check out our full discussion about asynchronous methods.

Examples

Wait for indexing of a new object:

1
2
3
4
5
6
$index->addObject(
  [
    'firstname' => 'Jimmie',
    'lastname'  => 'Barninger'
  ]
)->wait();

If you want to ensure multiple objects have been indexed, you only need to check the highest taskID (last operation)

Wait for indexing of a new object and send extra http header

1
2
3
4
5
6
7
8
$index->addObject(
  [
    'firstname' => 'Jimmie',
    'lastname'  => 'Barninger'
  ]
)->wait([
  'X-FORWARDED-FOR' => '94.228.178.246'
]);

Parameters

taskID
type: string
Required

taskID of the indexing task to wait for.

requestOptions
type: list
default: No requestOptions
Optional

A list of request options to send along with the query.

Response

No response

Did you find this page helpful?