| @@ 50-63 (lines=14) @@ | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function resolve($value = null) |
|
| 51 | { |
|
| 52 | if ($this->state()->equals(State::PENDING())) { |
|
| 53 | $this->actual = new FulfilledPromise($value); |
|
| 54 | ||
| 55 | while (!empty($this->deferreds)) { |
|
| 56 | /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */ |
|
| 57 | $deferred = array_shift($this->deferreds); |
|
| 58 | $deferred->resolve($value); |
|
| 59 | } |
|
| 60 | } else { |
|
| 61 | throw new \LogicException(\sprintf('A %s promise cannot be resolved', $this->state()->getValue())); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * {@inheritdoc} |
|
| @@ 68-80 (lines=13) @@ | ||
| 65 | /** |
|
| 66 | * {@inheritdoc} |
|
| 67 | */ |
|
| 68 | public function reject($reason = null) |
|
| 69 | { |
|
| 70 | if ($this->state()->equals(State::PENDING())) { |
|
| 71 | $this->actual = new RejectedPromise($reason); |
|
| 72 | while (!empty($this->deferreds)) { |
|
| 73 | /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */ |
|
| 74 | $deferred = array_shift($this->deferreds); |
|
| 75 | $deferred->reject($reason); |
|
| 76 | } |
|
| 77 | } else { |
|
| 78 | throw new \LogicException(\sprintf('A %s promise cannot be resolved', $this->state()->getValue())); |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * {@inheritdoc} |
|