| @@ 108-121 (lines=14) @@ | ||
| 105 | * |
|
| 106 | * @internal |
|
| 107 | */ |
|
| 108 | public function resolve(ResponseInterface $response) |
|
| 109 | { |
|
| 110 | if ($this->state !== HttpPromise::PENDING) { |
|
| 111 | throw new \RuntimeException('Promise is already resolved'); |
|
| 112 | } |
|
| 113 | ||
| 114 | $this->state = HttpPromise::FULFILLED; |
|
| 115 | $this->response = $response; |
|
| 116 | $onFulfilled = $this->onFulfilled; |
|
| 117 | ||
| 118 | if (null !== $onFulfilled) { |
|
| 119 | $onFulfilled($response); |
|
| 120 | } |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * Reject this promise |
|
| @@ 130-143 (lines=14) @@ | ||
| 127 | * |
|
| 128 | * @internal |
|
| 129 | */ |
|
| 130 | public function reject(Exception $exception) |
|
| 131 | { |
|
| 132 | if ($this->state !== HttpPromise::PENDING) { |
|
| 133 | throw new \RuntimeException('Promise is already resolved'); |
|
| 134 | } |
|
| 135 | ||
| 136 | $this->state = HttpPromise::REJECTED; |
|
| 137 | $this->exception = $exception; |
|
| 138 | $onRejected = $this->onRejected; |
|
| 139 | ||
| 140 | if (null !== $onRejected) { |
|
| 141 | $onRejected($exception); |
|
| 142 | } |
|
| 143 | } |
|
| 144 | ||
| 145 | /** |
|
| 146 | * {@inheritdoc} |
|