1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- declare(strict_types=1);
- namespace GuzzleHttp\Promise;
- class TaskQueue implements TaskQueueInterface
- {
- private $enableShutdown = true;
- private $queue = [];
- public function __construct(bool $withShutdown = true)
- {
- if ($withShutdown) {
- register_shutdown_function(function (): void {
- if ($this->enableShutdown) {
-
- $err = error_get_last();
- if (!$err || ($err['type'] ^ E_ERROR)) {
- $this->run();
- }
- }
- });
- }
- }
- public function isEmpty(): bool
- {
- return !$this->queue;
- }
- public function add(callable $task): void
- {
- $this->queue[] = $task;
- }
- public function run(): void
- {
- while ($task = array_shift($this->queue)) {
-
- $task();
- }
- }
-
- public function disableShutdown(): void
- {
- $this->enableShutdown = false;
- }
- }
|