Description
We want to provide a method in the MeiliSearch SDKs to wait for the asynchronous update.
Really useful in the testing part instead of using sleep
methods everwhere.
Naming
We chose the name WaitForPendingUpdate
for this method.
Except for the JS: getUpdateSync
because of JS convention.
The parameters should be named as updateId
, interval
and timeout
.
Details of the method
This method must have a break condition.
This method is a loop that checks the status of the update every interval
until a timeout
.
Both parameters must be customizable by the user.
If it's possible with the language, both parameters should be optional and the method should set default values if they are not defined by the user.
If it's not, like in Golang, another function (like a "wrapper") could be provided with default parameters.
If the method times out, it should return a TimeOut Exception
.
Example in PHP
public function waitForPendingUpdate($update_id, $timeout_in_ms = 2000, $interval_in_ms = 10)
{
$timeout_temp = 0;
while ($timeout_in_ms > $timeout_temp) {
$res = $this->getUpdateStatus($update_id);
if ('enqueued' != $res['status']) {
return $res;
}
$timeout_temp += $interval_in_ms;
usleep(1000 * $interval_in_ms);
}
throw new TimeOutException();
}
Testing part
At least, we should provide the following tests:
- Test that works with default values
- Test that works with custom
interval
andtimeout
- Test that returns an exception because of timeout: set a tiny value to
timeout
.
Steps
Do it in: