This documentation is for a deprecated version of JavaScript API client.
Some features and settings may be missing or their usage may have changed.
Refer to the documentation for the
latest version of JavaScript API client for up-to-date information.
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.
# Asynchronous call and wait_taskres=index.add_object({firstname: 'Jimmie',lastname: 'Barninger'})index.wait_task(res['taskID'])# Synchronous call, that does the wait_task internallyindex.add_object!({firstname: 'Jimmie',lastname: 'Barninger'})
index.addObject(newObject,completionHandler:{(content,error)->Voidiniferror!=nil{return}guardlettaskID=content!["taskID"]as?Intelse{return// could not retrieve task ID}index.waitTask(withID:taskID,completionHandler:{(content,error)->Voidiniferror==nil{print("New object is indexed!")}})})
BatchIndexingResponseresp=index.saveObject(newContact().setFirstname("Jimmie").setLastname("Barninger"));// All objects implementing the AlgoliaWaitableResponse interface// Can be awaited with the .waitTask() methodresp.waitTask();
letrequestOptions=RequestOptions()requestOptions.headers["X-Algolia-User-ID"]="user123"index.addObject(newObject,requestOptions:requestOptions,completionHandler:{(content,error)->Voidiniferror!=nil{return}guardlettaskID=content!["taskID"]as?Intelse{return// could not retrieve task ID}index.waitTask(withID:taskID,completionHandler:{(content,error)->Voidiniferror==nil{print("New object is indexed!")}})})
BatchIndexingResponseresp=index.saveObject(newContact().setFirstname("Jimmie").setLastname("Barninger"),newRequestOptions().addExtraHeader("X-Algolia-User-ID","user123"));// All objects implementing the AlgoliaWaitableResponse interface// Can be awaited with the .waitTask() methodresp.waitTask();
for{t<-client.execute{indexinto"toto"`object`MyObject("test")}r<-client.execute{waitFortasktfrom"toto"optionsRequestOptions(extraHeaders=Some(Map("X-Algolia-User-ID"=>"user123")))}}yield"indexing is done"
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.