Created
December 17, 2019 15:43
-
-
Save ubermuda/3cab1c6eb4d3428e092cfc5bcc6b6c0b to your computer and use it in GitHub Desktop.
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
<?php | |
use Clue\React\Mq\Queue; | |
use React\Promise\Promise; | |
class Job | |
{ | |
public function run() | |
{ | |
return new Promise(function() { | |
echo 'foo'.PHP_EOL; | |
sleep(1); | |
}); | |
} | |
} | |
$q = new Queue(3, null, static function(Job $job) { | |
return $job->run(); | |
}); | |
$i = 0; | |
$q(new Job()); | |
$q(new Job()); | |
$q(new Job()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Decent attempt. First, try to stay averse to writing long-running blocking code inside the event-loop (
sleep
in this case). Otherwise, I think a better example should be:Also, remember to have the loop running every time you run the queue.