Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Ds\Queue;
- class ThingDoer
- {
- private $jobs;
- private $running = false;
- public function __construct()
- {
- $this->jobs = new Queue;
- }
- private executeJob(Job $job)
- {
- // do stuff here
- }
- private run()
- {
- $this->running = true;
- while (!$this->jobs->isEmpty()) {
- yield from $this->executeJob($this->jobs->pop());
- }
- $this->running = false;
- }
- public function enqueueJob(Job $job)
- {
- $this->jobs->push($job);
- if (!$this->running) {
- resolve($this->run());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement