京东云

This commit is contained in:
“wanyongkang”
2024-05-28 17:04:50 +08:00
parent f644932afb
commit f3c7432100
672 changed files with 209344 additions and 6593 deletions

View File

@@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
namespace GuzzleHttp\Promise;
/**
@@ -9,16 +7,11 @@ namespace GuzzleHttp\Promise;
*
* Thenning off of this promise will invoke the onRejected callback
* immediately and ignore other callbacks.
*
* @final
*/
class RejectedPromise implements PromiseInterface
{
private $reason;
/**
* @param mixed $reason
*/
public function __construct($reason)
{
if (is_object($reason) && method_exists($reason, 'then')) {
@@ -33,7 +26,7 @@ class RejectedPromise implements PromiseInterface
public function then(
callable $onFulfilled = null,
callable $onRejected = null
): PromiseInterface {
) {
// If there's no onRejected callback then just return self.
if (!$onRejected) {
return $this;
@@ -42,7 +35,7 @@ class RejectedPromise implements PromiseInterface
$queue = Utils::queue();
$reason = $this->reason;
$p = new Promise([$queue, 'run']);
$queue->add(static function () use ($p, $reason, $onRejected): void {
$queue->add(static function () use ($p, $reason, $onRejected) {
if (Is::pending($p)) {
try {
// Return a resolved promise if onRejected does not throw.
@@ -50,6 +43,9 @@ class RejectedPromise implements PromiseInterface
} catch (\Throwable $e) {
// onRejected threw, so return a rejected promise.
$p->reject($e);
} catch (\Exception $e) {
// onRejected threw, so return a rejected promise.
$p->reject($e);
}
}
});
@@ -57,12 +53,12 @@ class RejectedPromise implements PromiseInterface
return $p;
}
public function otherwise(callable $onRejected): PromiseInterface
public function otherwise(callable $onRejected)
{
return $this->then(null, $onRejected);
}
public function wait(bool $unwrap = true)
public function wait($unwrap = true, $defaultDelivery = null)
{
if ($unwrap) {
throw Create::exceptionFor($this->reason);
@@ -71,24 +67,24 @@ class RejectedPromise implements PromiseInterface
return null;
}
public function getState(): string
public function getState()
{
return self::REJECTED;
}
public function resolve($value): void
public function resolve($value)
{
throw new \LogicException('Cannot resolve a rejected promise');
throw new \LogicException("Cannot resolve a rejected promise");
}
public function reject($reason): void
public function reject($reason)
{
if ($reason !== $this->reason) {
throw new \LogicException('Cannot reject a rejected promise');
throw new \LogicException("Cannot reject a rejected promise");
}
}
public function cancel(): void
public function cancel()
{
// pass
}