Promises/A implementation for PHP.
PromisorInterface
for objects that have a promise()
method.When::any()
not correctly unwrapping to a single result value$promiseOrValue
argument of When::resolve()
and When::reject()
is now optionalFeature: Significantly improve memory consumption and performance by only passing resolver args to resolver and canceller if callback requires them. Also use static callbacks without binding to promise, clean up canceller function reference when they are no longer needed and hide resolver and canceller references from call stack on PHP 7+. (#113, #115, #116, #117, #118, #119 and #123 by @clue)
These changes combined mean that rejecting promises with an Exception
should
no longer cause any internal circular references which could cause some unexpected
memory growth in previous versions. By explicitly avoiding and explicitly
cleaning up said references, we can avoid relying on PHP's circular garbage collector
to kick in which significantly improves performance when rejecting many promises.
Mark legacy progress support / notification API as deprecated (#112 by @clue)
Recommend rejecting promises by throwing an exception (#114 by @jsor)
Improve documentation to properly instantiate LazyPromise (#121 by @holtkamp)
Follower cancellation propagation was originally planned for this release but has been reverted for now and is planned for a future release. (#99 by @jsor and #122 by @clue)
Revert automatic cancellation of pending collection promises once the output promise resolves. This was introduced in 42d86b7 (PR #36, released in v2.3.0) and was both unintended and backward incompatible.
If you need automatic cancellation, you can use something like:
function allAndCancel(array $promises)
{
return \React\Promise\all($promises)
->always(function() use ($promises) {
foreach ($promises as $promise) {
if ($promise instanceof \React\Promise\CancellablePromiseInterface) {
$promise->cancel();
}
}
});
}
all()
and map()
functions now preserve the order of the array (#77).
Fix circular references when resolving a promise with itself (#71).
some()
not cancelling pending promises when too much input promises reject (16ff799).\Throwable
in the same way as \Exception
(#51 by @joshdifabio).resolve()
.
Any object that provides a then()
method is now assimilated to a trusted promise that follows the state of this thenable (#52).some()
and any()
for input arrays containing not enough items (#34).