Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\Adapter
AmpFutureAdapter::then
Method of the class: AmpFutureAdapter{}
No Hooks.
Returns
null. Nothing (null).
Usage
$AmpFutureAdapter = new AmpFutureAdapter(); $AmpFutureAdapter->then( $promise, ?callable $onFulfilled, ?callable $onRejected ): Promise;
- $promise(Promise) (required)
- .
- ?callable $onFulfilled
- .
Default:null - ?callable $onRejected
- .
Default:null
AmpFutureAdapter::then() AmpFutureAdapter::then code WC 10.9.1
public function then(Promise $promise, ?callable $onFulfilled = null, ?callable $onRejected = null): Promise
{
$future = $promise->adoptedPromise;
assert($future instanceof Future);
$next = async(static function () use ($future, $onFulfilled, $onRejected) {
try {
$value = $future->await();
} catch (\Throwable $reason) {
if ($onRejected === null) {
throw $reason;
}
return static::unwrapResult($onRejected($reason));
}
if ($onFulfilled === null) {
return $value;
}
return static::unwrapResult($onFulfilled($value));
});
return new Promise($next, $this);
}