-
Notifications
You must be signed in to change notification settings - Fork 44
Wait for Asynchronous Tasks
Clémentine Urquizar edited this page Jan 25, 2021
·
6 revisions
Some MeiliSearch operations are asynchronous, e.g. the document addition or the settings update. They will be put in a queue and will be executed in turn (asynchronously).
You might need to wait for the complete execution of this task before executing the rest of your code.
The wait_for_pending_update
method makes the task synchronous:
def wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
With wait_for_pending_update
:
puts 'Adding Le Petit Prince...'
response = index.add_document(id: 1, title: 'Le Petit Prince')
update_id = response['updateId']
wait_for_pending_update(update_id)
puts 'Addition done!'
Adding Le Petit Prince...
[MeiliSearch has finished adding the document]
Addition done!
Without wait_for_pending_update
:
puts 'Adding Le Petit Prince...'
response = index.add_document(id: 1, title: 'Le Petit Prince')
puts 'Addition done!'
Adding Le Petit Prince...
Addition done!
[MeiliSearch has now finished adding the document, but not before the "Addition done!" was written]