PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 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 All 35 releases
← All changes | includes/sdk/s3/GuzzleHttp/Promise/Coroutine.php +15 -23 1.2.91.4.1 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2
3 +declare (strict_types=1);
3 4 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Promise;
4 5
5 -use Exception;
6 6 use Generator;
7 7 use Throwable;
8 8 /**
9 9 * Creates a promise that is resolved using a generator that yields values or
@@ -25,9 +25,9 @@
25 25 * $promise = Promise\Coroutine::of(function () {
26 26 * $value = (yield createPromise('a'));
27 27 * try {
28 28 * $value = (yield createPromise($value . 'b'));
29 - * } catch (\Exception $e) {
29 + * } catch (\Throwable $e) {
30 30 * // The promise was rejected.
31 31 * }
32 32 * yield $value . 'c';
33 33 * });
@@ -38,9 +38,9 @@
38 38 * @param callable $generatorFn Generator function to wrap into a promise.
39 39 *
40 40 * @return Promise
41 41 *
42 - * @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
42 + * @see https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
43 43 */
44 44 final class Coroutine implements PromiseInterface
45 45 {
46 46 /**
@@ -57,9 +57,9 @@
57 57 private $result;
58 58 public function __construct(callable $generatorFn)
59 59 {
60 60 $this->generator = $generatorFn();
61 - $this->result = new Promise(function () {
61 + $this->result = new Promise(function () : void {
62 62 while (isset($this->currentPromise)) {
63 63 $this->currentPromise->wait();
64 64 }
65 65 });
@@ -64,10 +64,8 @@
64 64 }
65 65 });
66 66 try {
67 67 $this->nextCoroutine($this->generator->current());
68 - } catch (\Exception $exception) {
69 - $this->result->reject($exception);
70 68 } catch (Throwable $throwable) {
71 69 $this->result->reject($throwable);
72 70 }
73 71 }
@@ -72,45 +70,43 @@
72 70 }
73 71 }
74 72 /**
75 73 * Create a new coroutine.
76 - *
77 - * @return self
78 74 */
79 - public static function of(callable $generatorFn)
75 + public static function of(callable $generatorFn) : self
80 76 {
81 77 return new self($generatorFn);
82 78 }
83 - public function then(callable $onFulfilled = null, callable $onRejected = null)
79 + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface
84 80 {
85 81 return $this->result->then($onFulfilled, $onRejected);
86 82 }
87 - public function otherwise(callable $onRejected)
83 + public function otherwise(callable $onRejected) : PromiseInterface
88 84 {
89 85 return $this->result->otherwise($onRejected);
90 86 }
91 - public function wait($unwrap = \true)
87 + public function wait(bool $unwrap = \true)
92 88 {
93 89 return $this->result->wait($unwrap);
94 90 }
95 - public function getState()
91 + public function getState() : string
96 92 {
97 93 return $this->result->getState();
98 94 }
99 - public function resolve($value)
95 + public function resolve($value) : void
100 96 {
101 97 $this->result->resolve($value);
102 98 }
103 - public function reject($reason)
99 + public function reject($reason) : void
104 100 {
105 101 $this->result->reject($reason);
106 102 }
107 - public function cancel()
103 + public function cancel() : void
108 104 {
109 105 $this->currentPromise->cancel();
110 106 $this->result->cancel();
111 107 }
112 - private function nextCoroutine($yielded)
108 + private function nextCoroutine($yielded) : void
113 109 {
114 110 $this->currentPromise = Create::promiseFor($yielded)->then([$this, '_handleSuccess'], [$this, '_handleFailure']);
115 111 }
116 112 /**
@@ -115,9 +111,9 @@
115 111 }
116 112 /**
117 113 * @internal
118 114 */
119 - public function _handleSuccess($value)
115 + public function _handleSuccess($value) : void
120 116 {
121 117 unset($this->currentPromise);
122 118 try {
123 119 $next = $this->generator->send($value);
@@ -125,10 +121,8 @@
125 121 $this->nextCoroutine($next);
126 122 } else {
127 123 $this->result->resolve($value);
128 124 }
129 - } catch (Exception $exception) {
130 - $this->result->reject($exception);
131 125 } catch (Throwable $throwable) {
132 126 $this->result->reject($throwable);
133 127 }
134 128 }
@@ -134,9 +128,9 @@
134 128 }
135 129 /**
136 130 * @internal
137 131 */
138 - public function _handleFailure($reason)
132 + public function _handleFailure($reason) : void
139 133 {
140 134 unset($this->currentPromise);
141 135 try {
142 136 $nextYield = $this->generator->throw(Create::exceptionFor($reason));
@@ -141,10 +135,8 @@
141 135 try {
142 136 $nextYield = $this->generator->throw(Create::exceptionFor($reason));
143 137 // The throw was caught, so keep iterating on the coroutine
144 138 $this->nextCoroutine($nextYield);
145 - } catch (Exception $exception) {
146 - $this->result->reject($exception);
147 139 } catch (Throwable $throwable) {
148 140 $this->result->reject($throwable);
149 141 }
150 142 }