promise->then($wrappedOnFulfilled, $wrappedOnRejected); return $this; } /** * Get the state of the promise ("pending", "rejected", or "fulfilled"). * * The three states can be checked against the constants defined: * STATE_PENDING, STATE_FULFILLED, and STATE_REJECTED. * * @return IPromise::STATE_* * @since 28.0.0 */ public function getState(): string { $state = $this->promise->getState(); if ($state === PromiseInterface::FULFILLED) { return self::STATE_FULFILLED; } if ($state === PromiseInterface::REJECTED) { return self::STATE_REJECTED; } if ($state === PromiseInterface::PENDING) { return self::STATE_PENDING; } $this->logger->error('Unexpected promise state "{state}" returned by Guzzle', [ 'state' => $state, ]); return self::STATE_PENDING; } /** * Cancels the promise if possible. * * @link https://github.com/promises-aplus/cancellation-spec/issues/7 * @since 28.0.0 */ public function cancel(): void { $this->promise->cancel(); } /** * Waits until the promise completes if possible. * * Pass $unwrap as true to unwrap the result of the promise, either * returning the resolved value or throwing the rejected exception. * * If the promise cannot be waited on, then the promise will be rejected. * * @param bool $unwrap * * @return mixed * * @throws LogicException if the promise has no wait function or if the * promise does not settle after waiting. * @since 28.0.0 */ public function wait(bool $unwrap = true): mixed { return $this->promise->wait($unwrap); } }