A simple & classic debounce function. You provide a callable and specify a $wait
timer and get a callable (closure) back.
The closure takes the same arguments as the provided callable, but will only be executed $wait
seconds after being invoked. Invoking the closure again before $wait
seconds have passed will refresh the execution delay to the full $wait
seconds again.
This can be useful for example for detecting if a socket hasn't received data in, let's say, 10 seconds:
$loop = React\EventLoop\Factory::create();