PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.1
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / promises / src / TaskQueue.php

TaskQueue.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.1, at vendor_prefixed/guzzlehttp/promises/src/TaskQueue.php

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace YoastSEO_Vendor\GuzzleHttp\Promise;
5
6 /**
7 * A task queue that executes tasks in a FIFO order.
8 *
9 * This task queue class is used to settle promises asynchronously and
10 * maintains a constant stack size. You can use the task queue asynchronously
11 * by calling the `run()` function of the global task queue in an event loop.
12 *
13 * GuzzleHttp\Promise\Utils::queue()->run();
14 *
15 * @final
16 */
17 class TaskQueue implements \YoastSEO_Vendor\GuzzleHttp\Promise\TaskQueueInterface
18 {
19 private $enableShutdown = \true;
20 private $queue = [];
21 public function __construct(bool $withShutdown = \true)
22 {
23 if ($withShutdown) {
24 \register_shutdown_function(function () : void {
25 if ($this->enableShutdown) {
26 // Only run the tasks if an E_ERROR didn't occur.
27 $err = \error_get_last();
28 if (!$err || $err['type'] ^ \E_ERROR) {
29 $this->run();
30 }
31 }
32 });
33 }
34 }
35 public function isEmpty() : bool
36 {
37 return !$this->queue;
38 }
39 public function add(callable $task) : void
40 {
41 $this->queue[] = $task;
42 }
43 public function run() : void
44 {
45 while ($task = \array_shift($this->queue)) {
46 /** @var callable $task */
47 $task();
48 }
49 }
50 /**
51 * The task queue will be run and exhausted by default when the process
52 * exits IFF the exit is not the result of a PHP E_ERROR error.
53 *
54 * You can disable running the automatic shutdown of the queue by calling
55 * this function. If you disable the task queue shutdown process, then you
56 * MUST either run the task queue (as a result of running your event loop
57 * or manually using the run() method) or wait on each outstanding promise.
58 *
59 * Note: This shutdown will occur before any destructors are triggered.
60 */
61 public function disableShutdown() : void
62 {
63 $this->enableShutdown = \false;
64 }
65 }
66