16 if (method_exists($value,
'then')) {
17 throw new \InvalidArgumentException(
18 'You cannot create a FulfilledPromise with a promise.');
21 $this->value = $value;
25 callable $onFulfilled =
null,
26 callable $onRejected =
null
34 $p =
new Promise([$queue,
'run']);
35 $value = $this->value;
36 $queue->add(
static function () use ($p, $value, $onFulfilled) {
37 if ($p->getState() === self::PENDING) {
39 $p->resolve($onFulfilled($value));
40 } catch (\Throwable $e) {
42 }
catch (\Exception $e) {
53 return $this->
then(
null, $onRejected);
56 public function wait($unwrap =
true, $defaultDelivery =
null)
58 return $unwrap ? $this->value :
null;
68 if ($value !== $this->value) {
69 throw new \LogicException(
"Cannot resolve a fulfilled promise");
75 throw new \LogicException(
"Cannot reject a fulfilled promise");