| @@ -1,8 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 5 | 3 | namespace Depicter\GuzzleHttp\Promise; |
| 6 | 4 | |
| 7 | 5 | /** |
| 8 | 6 | * A task queue that executes tasks in a FIFO order. |
| @@ -11,10 +9,8 @@ | ||
| 11 | 9 | * maintains a constant stack size. You can use the task queue asynchronously |
| 12 | 10 | * by calling the `run()` function of the global task queue in an event loop. |
| 13 | 11 | * |
| 14 | 12 | * Depicter\GuzzleHttp\Promise\Utils::queue()->run(); |
| 15 | - * | |
| 16 | - * @final | |
| 17 | 13 | */ |
| 18 | 14 | class TaskQueue implements TaskQueueInterface |
| 19 | 15 | { |
| 20 | 16 | private $enableShutdown = true; |
| @@ -19,12 +15,12 @@ | ||
| 19 | 15 | { |
| 20 | 16 | private $enableShutdown = true; |
| 21 | 17 | private $queue = []; |
| 22 | 18 | |
| 23 | - public function __construct(bool $withShutdown = true) | |
| 19 | + public function __construct($withShutdown = true) | |
| 24 | 20 | { |
| 25 | 21 | if ($withShutdown) { |
| 26 | - register_shutdown_function(function (): void { | |
| 22 | + register_shutdown_function(function () { | |
| 27 | 23 | if ($this->enableShutdown) { |
| 28 | 24 | // Only run the tasks if an E_ERROR didn't occur. |
| 29 | 25 | $err = error_get_last(); |
| 30 | 26 | if (!$err || ($err['type'] ^ E_ERROR)) { |
| @@ -34,19 +30,19 @@ | ||
| 34 | 30 | }); |
| 35 | 31 | } |
| 36 | 32 | } |
| 37 | 33 | |
| 38 | - public function isEmpty(): bool | |
| 34 | + public function isEmpty() | |
| 39 | 35 | { |
| 40 | 36 | return !$this->queue; |
| 41 | 37 | } |
| 42 | 38 | |
| 43 | - public function add(callable $task): void | |
| 39 | + public function add(callable $task) | |
| 44 | 40 | { |
| 45 | 41 | $this->queue[] = $task; |
| 46 | 42 | } |
| 47 | 43 | |
| 48 | - public function run(): void | |
| 44 | + public function run() | |
| 49 | 45 | { |
| 50 | 46 | while ($task = array_shift($this->queue)) { |
| 51 | 47 | /** @var callable $task */ |
| 52 | 48 | $task(); |
| @@ -63,9 +59,9 @@ | ||
| 63 | 59 | * or manually using the run() method) or wait on each outstanding promise. |
| 64 | 60 | * |
| 65 | 61 | * Note: This shutdown will occur before any destructors are triggered. |
| 66 | 62 | */ |
| 67 | - public function disableShutdown(): void | |
| 63 | + public function disableShutdown() | |
| 68 | 64 | { |
| 69 | 65 | $this->enableShutdown = false; |
| 70 | 66 | } |
| 71 | 67 | } |