PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.7
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 18.7, at vendor_prefixed/guzzlehttp/promises/src/TaskQueue.php

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