function promise_for in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/guzzlehttp/promises/src/functions.php \GuzzleHttp\Promise\promise_for()
Creates a promise for a value if the value is not a promise.
Parameters
mixed $value Promise or value.:
Return value
2 calls to promise_for()
- EachPromise::addPending in vendor/
guzzlehttp/ promises/ src/ EachPromise.php - Promise::then in vendor/
guzzlehttp/ promises/ src/ Promise.php - Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.
File
- vendor/
guzzlehttp/ promises/ src/ functions.php, line 60
Namespace
GuzzleHttp\PromiseCode
function promise_for($value) {
if ($value instanceof PromiseInterface) {
return $value;
}
// Return a Guzzle promise that shadows the given promise.
if (method_exists($value, 'then')) {
$wfn = method_exists($value, 'wait') ? [
$value,
'wait',
] : null;
$cfn = method_exists($value, 'cancel') ? [
$value,
'cancel',
] : null;
$promise = new Promise($wfn, $cfn);
$value
->then([
$promise,
'resolve',
], [
$promise,
'reject',
]);
return $promise;
}
return new FulfilledPromise($value);
}