v1.1.4
This commit is contained in:
parent
d6e6011c3d
commit
1dd5809016
5 changed files with 21760 additions and 3778 deletions
5
vendor/guzzlehttp/promises/src/Coroutine.php
vendored
5
vendor/guzzlehttp/promises/src/Coroutine.php
vendored
|
|
@ -117,7 +117,10 @@ final class Coroutine implements PromiseInterface
|
|||
|
||||
public function cancel(): void
|
||||
{
|
||||
$this->currentPromise->cancel();
|
||||
if (isset($this->currentPromise)) {
|
||||
$this->currentPromise->cancel();
|
||||
}
|
||||
|
||||
$this->result->cancel();
|
||||
}
|
||||
|
||||
|
|
|
|||
10
vendor/guzzlehttp/promises/src/Create.php
vendored
10
vendor/guzzlehttp/promises/src/Create.php
vendored
|
|
@ -74,6 +74,16 @@ final class Create
|
|||
return new \ArrayIterator($value);
|
||||
}
|
||||
|
||||
if (!is_iterable($value)) {
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/promises',
|
||||
'2.5',
|
||||
'Passing a non-iterable to %s::%s() is deprecated; guzzlehttp/promises 3.0 will require an iterable.',
|
||||
__CLASS__,
|
||||
__FUNCTION__
|
||||
);
|
||||
}
|
||||
|
||||
return new \ArrayIterator([$value]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
vendor/guzzlehttp/promises/src/Each.php
vendored
23
vendor/guzzlehttp/promises/src/Each.php
vendored
|
|
@ -26,6 +26,8 @@ final class Each
|
|||
?callable $onFulfilled = null,
|
||||
?callable $onRejected = null
|
||||
): PromiseInterface {
|
||||
$iterable = self::prepareIterable($iterable, __FUNCTION__);
|
||||
|
||||
return (new EachPromise($iterable, [
|
||||
'fulfilled' => $onFulfilled,
|
||||
'rejected' => $onRejected,
|
||||
|
|
@ -49,6 +51,8 @@ final class Each
|
|||
?callable $onFulfilled = null,
|
||||
?callable $onRejected = null
|
||||
): PromiseInterface {
|
||||
$iterable = self::prepareIterable($iterable, __FUNCTION__);
|
||||
|
||||
return (new EachPromise($iterable, [
|
||||
'fulfilled' => $onFulfilled,
|
||||
'rejected' => $onRejected,
|
||||
|
|
@ -69,6 +73,8 @@ final class Each
|
|||
$concurrency,
|
||||
?callable $onFulfilled = null
|
||||
): PromiseInterface {
|
||||
$iterable = self::prepareIterable($iterable, __FUNCTION__);
|
||||
|
||||
return self::ofLimit(
|
||||
$iterable,
|
||||
$concurrency,
|
||||
|
|
@ -78,4 +84,21 @@ final class Each
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static function prepareIterable($iterable, string $method): iterable
|
||||
{
|
||||
if (is_iterable($iterable)) {
|
||||
return $iterable;
|
||||
}
|
||||
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/promises',
|
||||
'2.5',
|
||||
'Passing a non-iterable to %s::%s() is deprecated; guzzlehttp/promises 3.0 will require an iterable.',
|
||||
self::class,
|
||||
$method
|
||||
);
|
||||
|
||||
return [$iterable];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
vendor/guzzlehttp/promises/src/EachPromise.php
vendored
25
vendor/guzzlehttp/promises/src/EachPromise.php
vendored
|
|
@ -57,6 +57,18 @@ class EachPromise implements PromisorInterface
|
|||
*/
|
||||
public function __construct($iterable, array $config = [])
|
||||
{
|
||||
if (!is_iterable($iterable)) {
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/promises',
|
||||
'2.5',
|
||||
'Passing a non-iterable to %s::%s() is deprecated; guzzlehttp/promises 3.0 will require an iterable.',
|
||||
__CLASS__,
|
||||
__FUNCTION__
|
||||
);
|
||||
|
||||
$iterable = [$iterable];
|
||||
}
|
||||
|
||||
$this->iterable = Create::iterFor($iterable);
|
||||
|
||||
if (isset($config['concurrency'])) {
|
||||
|
|
@ -84,6 +96,19 @@ class EachPromise implements PromisorInterface
|
|||
/** @psalm-assert Promise $this->aggregate */
|
||||
$this->iterable->rewind();
|
||||
$this->refillPending();
|
||||
if (!$this->pending) {
|
||||
Utils::queue()->add(function (): void {
|
||||
if (!$this->aggregate || Is::settled($this->aggregate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->checkIfFinished();
|
||||
} catch (\Throwable $e) {
|
||||
$this->aggregate->reject($e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->aggregate->reject($e);
|
||||
}
|
||||
|
|
|
|||
48
vendor/guzzlehttp/promises/src/Utils.php
vendored
48
vendor/guzzlehttp/promises/src/Utils.php
vendored
|
|
@ -76,9 +76,15 @@ final class Utils
|
|||
'state' => PromiseInterface::FULFILLED,
|
||||
'value' => $promise->wait(),
|
||||
];
|
||||
} catch (RejectionException $e) {
|
||||
return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()];
|
||||
} catch (\Throwable $e) {
|
||||
if ($e instanceof AggregateException) {
|
||||
return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
|
||||
}
|
||||
|
||||
if ($e instanceof RejectionException) {
|
||||
return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()];
|
||||
}
|
||||
|
||||
return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +101,8 @@ final class Utils
|
|||
*/
|
||||
public static function inspectAll($promises): array
|
||||
{
|
||||
$promises = self::prepareIterable($promises, __FUNCTION__);
|
||||
|
||||
$results = [];
|
||||
foreach ($promises as $key => $promise) {
|
||||
$results[$key] = self::inspect($promise);
|
||||
|
|
@ -116,6 +124,8 @@ final class Utils
|
|||
*/
|
||||
public static function unwrap($promises): array
|
||||
{
|
||||
$promises = self::prepareIterable($promises, __FUNCTION__);
|
||||
|
||||
$results = [];
|
||||
foreach ($promises as $key => $promise) {
|
||||
$results[$key] = $promise->wait();
|
||||
|
|
@ -137,6 +147,8 @@ final class Utils
|
|||
*/
|
||||
public static function all($promises, bool $recursive = false): PromiseInterface
|
||||
{
|
||||
$promises = self::prepareIterable($promises, __FUNCTION__);
|
||||
|
||||
$results = [];
|
||||
$promise = Each::of(
|
||||
$promises,
|
||||
|
|
@ -185,6 +197,8 @@ final class Utils
|
|||
*/
|
||||
public static function some(int $count, $promises): PromiseInterface
|
||||
{
|
||||
$promises = self::prepareIterable($promises, __FUNCTION__);
|
||||
|
||||
$results = [];
|
||||
$rejections = [];
|
||||
|
||||
|
|
@ -225,6 +239,8 @@ final class Utils
|
|||
*/
|
||||
public static function any($promises): PromiseInterface
|
||||
{
|
||||
$promises = self::prepareIterable($promises, __FUNCTION__);
|
||||
|
||||
return self::some(1, $promises)->then(function ($values) {
|
||||
return $values[0];
|
||||
});
|
||||
|
|
@ -242,6 +258,8 @@ final class Utils
|
|||
*/
|
||||
public static function settle($promises): PromiseInterface
|
||||
{
|
||||
$promises = self::prepareIterable($promises, __FUNCTION__);
|
||||
|
||||
$results = [];
|
||||
|
||||
return Each::of(
|
||||
|
|
@ -258,4 +276,30 @@ final class Utils
|
|||
return $results;
|
||||
});
|
||||
}
|
||||
|
||||
private static function prepareIterable($promises, string $method): iterable
|
||||
{
|
||||
if (is_iterable($promises)) {
|
||||
return $promises;
|
||||
}
|
||||
|
||||
self::triggerNonIterableDeprecation($promises, $method);
|
||||
|
||||
return [$promises];
|
||||
}
|
||||
|
||||
private static function triggerNonIterableDeprecation($promises, string $method): void
|
||||
{
|
||||
if (is_iterable($promises)) {
|
||||
return;
|
||||
}
|
||||
|
||||
\trigger_deprecation(
|
||||
'guzzlehttp/promises',
|
||||
'2.5',
|
||||
'Passing a non-iterable to %s::%s() is deprecated; guzzlehttp/promises 3.0 will require an iterable.',
|
||||
self::class,
|
||||
$method
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue