This documentation is for a deprecated version of Ruby API client .
Some features and settings may be missing or their usage may have changed.
Refer to the documentation for the
latest version of Ruby 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'})
structContact:Codable{letfirstName:StringletlastName:String}letobject=Contact(firstName:"Jimmie",lastName:"Barninger")tryindex.saveObject(object,autoGeneratingObjectID:true){resultinifcase.success(letwaitableWrapper)=result{waitableWrapper.wait(){resultinifcase.success(letresponse)=result{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();
structContact:Codable{letfirstName:StringletlastName:String}letobject=Contact(firstName:"Jimmie",lastName:"Barninger")varrequestOptions=RequestOptions()requestOptions.headers=["X-Algolia-User-ID":"user123"]tryindex.saveObject(object,autoGeneratingObjectID:true){resultinifcase.success(letwaitableWrapper)=result{waitableWrapper.wait(requestOptions:requestOptions){resultinifcase.success(letresponse)=result{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.