summaryrefslogtreecommitdiff
path: root/vendor/guzzlehttp/promises/src/EachPromise.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-10-20 16:44:35 +0300
committerAndrew Dolgov <[email protected]>2023-10-20 16:44:35 +0300
commit8bec661288b276c98bdb0e773e5f4d5275dc4c87 (patch)
tree8617ebe581c62fc46a7881aa61801ebce9d3c603 /vendor/guzzlehttp/promises/src/EachPromise.php
parent540438c2eb5452bacad30c247906bfa287f2da1d (diff)
update AWK SDKHEADmaster
Diffstat (limited to 'vendor/guzzlehttp/promises/src/EachPromise.php')
-rw-r--r--vendor/guzzlehttp/promises/src/EachPromise.php43
1 files changed, 23 insertions, 20 deletions
diff --git a/vendor/guzzlehttp/promises/src/EachPromise.php b/vendor/guzzlehttp/promises/src/EachPromise.php
index 280d799..28dd979 100644
--- a/vendor/guzzlehttp/promises/src/EachPromise.php
+++ b/vendor/guzzlehttp/promises/src/EachPromise.php
@@ -1,10 +1,14 @@
<?php
+declare(strict_types=1);
+
namespace GuzzleHttp\Promise;
/**
* Represents a promise that iterates over many promises and invokes
* side-effect functions in the process.
+ *
+ * @final
*/
class EachPromise implements PromisorInterface
{
@@ -69,7 +73,7 @@ class EachPromise implements PromisorInterface
}
/** @psalm-suppress InvalidNullableReturnType */
- public function promise()
+ public function promise(): PromiseInterface
{
if ($this->aggregate) {
return $this->aggregate;
@@ -82,21 +86,18 @@ class EachPromise implements PromisorInterface
$this->refillPending();
} catch (\Throwable $e) {
$this->aggregate->reject($e);
- } catch (\Exception $e) {
- $this->aggregate->reject($e);
}
/**
* @psalm-suppress NullableReturnStatement
- * @phpstan-ignore-next-line
*/
return $this->aggregate;
}
- private function createPromise()
+ private function createPromise(): void
{
$this->mutex = false;
- $this->aggregate = new Promise(function () {
+ $this->aggregate = new Promise(function (): void {
if ($this->checkIfFinished()) {
return;
}
@@ -113,7 +114,7 @@ class EachPromise implements PromisorInterface
});
// Clear the references when the promise is resolved.
- $clearFn = function () {
+ $clearFn = function (): void {
$this->iterable = $this->concurrency = $this->pending = null;
$this->onFulfilled = $this->onRejected = null;
$this->nextPendingIndex = 0;
@@ -122,11 +123,13 @@ class EachPromise implements PromisorInterface
$this->aggregate->then($clearFn, $clearFn);
}
- private function refillPending()
+ private function refillPending(): void
{
if (!$this->concurrency) {
// Add all pending promises.
- while ($this->addPending() && $this->advanceIterator());
+ while ($this->addPending() && $this->advanceIterator()) {
+ }
+
return;
}
@@ -147,10 +150,11 @@ class EachPromise implements PromisorInterface
// next value to yield until promise callbacks are called.
while (--$concurrency
&& $this->advanceIterator()
- && $this->addPending());
+ && $this->addPending()) {
+ }
}
- private function addPending()
+ private function addPending(): bool
{
if (!$this->iterable || !$this->iterable->valid()) {
return false;
@@ -164,7 +168,7 @@ class EachPromise implements PromisorInterface
$idx = $this->nextPendingIndex++;
$this->pending[$idx] = $promise->then(
- function ($value) use ($idx, $key) {
+ function ($value) use ($idx, $key): void {
if ($this->onFulfilled) {
call_user_func(
$this->onFulfilled,
@@ -175,7 +179,7 @@ class EachPromise implements PromisorInterface
}
$this->step($idx);
},
- function ($reason) use ($idx, $key) {
+ function ($reason) use ($idx, $key): void {
if ($this->onRejected) {
call_user_func(
$this->onRejected,
@@ -191,7 +195,7 @@ class EachPromise implements PromisorInterface
return true;
}
- private function advanceIterator()
+ private function advanceIterator(): bool
{
// Place a lock on the iterator so that we ensure to not recurse,
// preventing fatal generator errors.
@@ -204,19 +208,17 @@ class EachPromise implements PromisorInterface
try {
$this->iterable->next();
$this->mutex = false;
+
return true;
} catch (\Throwable $e) {
$this->aggregate->reject($e);
$this->mutex = false;
- return false;
- } catch (\Exception $e) {
- $this->aggregate->reject($e);
- $this->mutex = false;
+
return false;
}
}
- private function step($idx)
+ private function step(int $idx): void
{
// If the promise was already resolved, then ignore this step.
if (Is::settled($this->aggregate)) {
@@ -234,11 +236,12 @@ class EachPromise implements PromisorInterface
}
}
- private function checkIfFinished()
+ private function checkIfFinished(): bool
{
if (!$this->pending && !$this->iterable->valid()) {
// Resolve the promise if there's nothing left to do.
$this->aggregate->resolve(null);
+
return true;
}