diff options
Diffstat (limited to 'vendor/guzzlehttp/promises/src/Coroutine.php')
-rw-r--r-- | vendor/guzzlehttp/promises/src/Coroutine.php | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/vendor/guzzlehttp/promises/src/Coroutine.php b/vendor/guzzlehttp/promises/src/Coroutine.php index 670da47..0b5b9c0 100644 --- a/vendor/guzzlehttp/promises/src/Coroutine.php +++ b/vendor/guzzlehttp/promises/src/Coroutine.php @@ -1,8 +1,9 @@ <?php +declare(strict_types=1); + namespace GuzzleHttp\Promise; -use Exception; use Generator; use Throwable; @@ -27,7 +28,7 @@ use Throwable; * $value = (yield createPromise('a')); * try { * $value = (yield createPromise($value . 'b')); - * } catch (\Exception $e) { + * } catch (\Throwable $e) { * // The promise was rejected. * } * yield $value . 'c'; @@ -40,7 +41,7 @@ use Throwable; * * @return Promise * - * @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration + * @see https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration */ final class Coroutine implements PromiseInterface { @@ -62,15 +63,13 @@ final class Coroutine implements PromiseInterface public function __construct(callable $generatorFn) { $this->generator = $generatorFn(); - $this->result = new Promise(function () { + $this->result = new Promise(function (): void { while (isset($this->currentPromise)) { $this->currentPromise->wait(); } }); try { $this->nextCoroutine($this->generator->current()); - } catch (\Exception $exception) { - $this->result->reject($exception); } catch (Throwable $throwable) { $this->result->reject($throwable); } @@ -78,10 +77,8 @@ final class Coroutine implements PromiseInterface /** * Create a new coroutine. - * - * @return self */ - public static function of(callable $generatorFn) + public static function of(callable $generatorFn): self { return new self($generatorFn); } @@ -89,42 +86,42 @@ final class Coroutine implements PromiseInterface public function then( callable $onFulfilled = null, callable $onRejected = null - ) { + ): PromiseInterface { return $this->result->then($onFulfilled, $onRejected); } - public function otherwise(callable $onRejected) + public function otherwise(callable $onRejected): PromiseInterface { return $this->result->otherwise($onRejected); } - public function wait($unwrap = true) + public function wait(bool $unwrap = true) { return $this->result->wait($unwrap); } - public function getState() + public function getState(): string { return $this->result->getState(); } - public function resolve($value) + public function resolve($value): void { $this->result->resolve($value); } - public function reject($reason) + public function reject($reason): void { $this->result->reject($reason); } - public function cancel() + public function cancel(): void { $this->currentPromise->cancel(); $this->result->cancel(); } - private function nextCoroutine($yielded) + private function nextCoroutine($yielded): void { $this->currentPromise = Create::promiseFor($yielded) ->then([$this, '_handleSuccess'], [$this, '_handleFailure']); @@ -133,7 +130,7 @@ final class Coroutine implements PromiseInterface /** * @internal */ - public function _handleSuccess($value) + public function _handleSuccess($value): void { unset($this->currentPromise); try { @@ -143,8 +140,6 @@ final class Coroutine implements PromiseInterface } else { $this->result->resolve($value); } - } catch (Exception $exception) { - $this->result->reject($exception); } catch (Throwable $throwable) { $this->result->reject($throwable); } @@ -153,15 +148,13 @@ final class Coroutine implements PromiseInterface /** * @internal */ - public function _handleFailure($reason) + public function _handleFailure($reason): void { unset($this->currentPromise); try { $nextYield = $this->generator->throw(Create::exceptionFor($reason)); // The throw was caught, so keep iterating on the coroutine $this->nextCoroutine($nextYield); - } catch (Exception $exception) { - $this->result->reject($exception); } catch (Throwable $throwable) { $this->result->reject($throwable); } |