: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
declare (strict_types=1);
namespace YoastSEO_Vendor\GuzzleHttp\Promise;
* Creates a promise that is resolved using a generator that yields values or
* promises (somewhat similar to C#'s async keyword).
* When called, the Coroutine::of method will start an instance of the generator
* and returns a promise that is fulfilled with its final yielded value.
* Control is returned back to the generator when the yielded promise settles.
* This can lead to less verbose code when doing lots of sequential async calls
* with minimal processing in between.
* use GuzzleHttp\Promise;
* function createPromise($value) {
* return new Promise\FulfilledPromise($value);
* $promise = Promise\Coroutine::of(function () {
* $value = (yield createPromise('a'));
* $value = (yield createPromise($value . 'b'));
* } catch (\Throwable $e) {
* // The promise was rejected.
* $promise->then(function ($v) { echo $v; });
* @param callable $generatorFn Generator function to wrap into a promise.
* @see https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
final class Coroutine implements \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
* @var PromiseInterface|null
public function __construct(callable $generatorFn)
$this->generator = $generatorFn();
$this->result = new \YoastSEO_Vendor\GuzzleHttp\Promise\Promise(function () : void {
while (isset($this->currentPromise)) {
$this->currentPromise->wait();
$this->nextCoroutine($this->generator->current());
} catch (\Throwable $throwable) {
$this->result->reject($throwable);
* Create a new coroutine.
public static function of(callable $generatorFn) : self
return new self($generatorFn);
public function then(callable $onFulfilled = null, callable $onRejected = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
return $this->result->then($onFulfilled, $onRejected);
public function otherwise(callable $onRejected) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
return $this->result->otherwise($onRejected);
public function wait(bool $unwrap = \true)
return $this->result->wait($unwrap);
public function getState() : string
return $this->result->getState();
public function resolve($value) : void
$this->result->resolve($value);
public function reject($reason) : void
$this->result->reject($reason);
public function cancel() : void
$this->currentPromise->cancel();
private function nextCoroutine($yielded) : void
$this->currentPromise = \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($yielded)->then([$this, '_handleSuccess'], [$this, '_handleFailure']);
public function _handleSuccess($value) : void
unset($this->currentPromise);
$next = $this->generator->send($value);
if ($this->generator->valid()) {
$this->nextCoroutine($next);
$this->result->resolve($value);
} catch (\Throwable $throwable) {
$this->result->reject($throwable);
public function _handleFailure($reason) : void
unset($this->currentPromise);
$nextYield = $this->generator->throw(\YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($reason));
// The throw was caught, so keep iterating on the coroutine
$this->nextCoroutine($nextYield);
} catch (\Throwable $throwable) {
$this->result->reject($throwable);