function Create::promiseFor
Creates a promise for a value if the value is not a promise.
Parameters
mixed $value Promise or value.:
2 calls to Create::promiseFor()
- 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/ Create.php, line 14
Class
Namespace
GuzzleHttp\PromiseCode
public static function promiseFor($value) : PromiseInterface {
if ($value instanceof PromiseInterface) {
return $value;
}
// Return a Guzzle promise that shadows the given promise.
if (is_object($value) && 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);
}