PluginProbe
Media Cloud Sync / 1.0.2
Media Cloud Sync v1.0.2
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Promise / TaskQueue.php

TaskQueue.php in Media Cloud Sync 1.0.2, at includes/sdk/s3/GuzzleHttp/Promise/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 Dudlewebs\WPMCS\s3\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 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