16 if (method_exists($reason,
'then')) {
17 throw new \InvalidArgumentException(
18 'You cannot create a RejectedPromise with a promise.');
21 $this->reason = $reason;
25 callable $onFulfilled =
null,
26 callable $onRejected =
null
34 $reason = $this->reason;
35 $p =
new Promise([$queue,
'run']);
36 $queue->add(
static function () use ($p, $reason, $onRejected) {
37 if ($p->getState() === self::PENDING) {
40 $p->resolve($onRejected($reason));
41 } catch (\Throwable $e) {
44 }
catch (\Exception $e) {
56 return $this->
then(
null, $onRejected);
59 public function wait($unwrap =
true, $defaultDelivery =
null)
73 throw new \LogicException(
"Cannot resolve a rejected promise");
78 if ($reason !== $this->reason) {
79 throw new \LogicException(
"Cannot reject a rejected promise");