PluginProbe
WP-Stateless – Google Cloud Storage / 2.1.4
WP-Stateless – Google Cloud Storage v2.1.4
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / Google / vendor / react / promise / src / CancellationQueue.php

CancellationQueue.php in WP-Stateless – Google Cloud Storage 2.1.4, at lib/Google/vendor/react/promise/src/CancellationQueue.php

56 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace React\Promise;
4
5 class CancellationQueue
6 {
7 private $started = false;
8 private $queue = [];
9
10 public function __invoke()
11 {
12 if ($this->started) {
13 return;
14 }
15
16 $this->started = true;
17 $this->drain();
18 }
19
20 public function enqueue($cancellable)
21 {
22 if (!method_exists($cancellable, 'then') || !method_exists($cancellable, 'cancel')) {
23 return;
24 }
25
26 $length = array_push($this->queue, $cancellable);
27
28 if ($this->started && 1 === $length) {
29 $this->drain();
30 }
31 }
32
33 private function drain()
34 {
35 for ($i = key($this->queue); isset($this->queue[$i]); $i++) {
36 $cancellable = $this->queue[$i];
37
38 $exception = null;
39
40 try {
41 $cancellable->cancel();
42 } catch (\Throwable $exception) {
43 } catch (\Exception $exception) {
44 }
45
46 unset($this->queue[$i]);
47
48 if ($exception) {
49 throw $exception;
50 }
51 }
52
53 $this->queue = [];
54 }
55 }
56