algolia/algoliasearch-client-php

Using non-blocking sleep method

alexander-schranz opened this issue · 1 comments

  • Algolia Client Version: v3.3.2
  • Language Version: 8.1.3

Description

I'm currently implementing an abstraction around search engines and was thinking about calling $task->wait(); in a async react-php method. But as the wait is using sleep / usleep it is blocking method. Maybe it would make sense to move to a non-blocking method or look if example a non block variant like \React\Promise\Timer\sleep(1.0) exist use that when install else fallback to usleep/sleep.

I'm not an expert with async and didn't yet test out the things more. So it could also be that this totally does not make any sense as other core things are already blocking. Just stumble over it and thought it is maybe worth to great an issue for it.

Reference from ReactPHP Async doc that sleep is blocking: https://github.com/reactphp/async#async

Hi @alexander-schranz !

Thank you for proposing this. The wait / waitTask method is synchronous by design, as it's meant to be blocking code execution until a task in Algolia has finalized. For a version compatible with react-php, I'd recommend implementing a custom method in your code that follows the same logic as the waitTask method, but with the sleep replaced with the variant you suggested.

I hope this helps, let me know if you have any question. I'm closing the issue for now, but if there's a lot of demand for this feature we may want to reconsider it.