Created
August 27, 2019 07:47
-
-
Save mmoreram/552b068135ace0a0a1e7fb691a89f07c to your computer and use it in GitHub Desktop.
ReactPHP Loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Make async sleep | |
* | |
* @param float $timeout | |
* @param LoopInterface $loop | |
* | |
* @return PromiseInterface | |
*/ | |
function sleep(float $timeout, LoopInterface $loop) { | |
$deferred = new Deferred(); | |
$loop->addTimer($timeout, function() use ($deferred) { | |
$deferred->resolve(); | |
}); | |
return $deferred->promise(); | |
} | |
return sleep(1, $loop); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment