Promise Changelog

2023

3.1.0 (2023-11-16) Release on GitHub

  • Feature: Full PHP 8.3 compatibility.
    (#255 by @clue)

  • Feature: Describe all callable arguments with types for Promise and Deferred.
    (#253 by @clue)

  • Update test suite and minor documentation improvements.
    (#251 by @ondrejmirtes and #250 by @SQKo)


2.11.0 (2023-11-16) Release on GitHub

This is a compatibility release to ensure a smooth upgrade path for those not yet
on Promise v3. We encourage upgrading to the latest version when possible, as
Promise v3 will be the way forward for this project.

  • Feature: Full PHP 8.3 compatibility.
    (#256 by @clue)

1.3.0 (2023-11-16) Release on GitHub

This is a compatibility release to ensure a smooth upgrade path for those not
yet on Promise v3. We encourage upgrading to the latest version when possible,
as Promise v3 will be the way forward for this project.


3.0.0 (2023-07-11) Release on GitHub

A major new feature release, see release announcement.

  • We'd like to emphasize that this component is production ready and battle-tested.
    We plan to support all long-term support (LTS) releases for at least 24 months,
    so you have a rock-solid foundation to build on top of.

  • The v3 release will be the way forward for this package. However, we will still
    actively support v2 and v1 to provide a smooth upgrade path for those not yet
    on the latest versions.

This update involves some major new features and a minor BC break over the
v2.0.0 release. We've tried hard to avoid BC breaks where possible and
minimize impact otherwise. We expect that most consumers of this package will be
affected by BC breaks, but updating should take no longer than a few minutes.
See below for more details:

  • BC break: PHP 8.1+ recommended, PHP 7.1+ required.
    (#138 and #149 by @WyriHaximus)

  • Feature / BC break: The PromiseInterface now includes the functionality of the old ExtendedPromiseInterface and CancellablePromiseInterface.
    Each promise now always includes the then(), catch(), finally() and cancel() methods.
    The new catch() and finally() methods replace the deprecated otherwise() and always() methods which continue to exist for BC reasons.
    The old ExtendedPromiseInterface and CancellablePromiseInterface are no longer needed and have been removed as a consequence.
    (#75 by @jsor and #208 by @clue and @WyriHaximus)

    // old (multiple interfaces may or may not be implemented)
    assert($promise instanceof PromiseInterface);
    assert(method_exists($promise, 'then'));
    if ($promise instanceof ExtendedPromiseInterface) { assert(method_exists($promise, 'otherwise')); }
    if ($promise instanceof ExtendedPromiseInterface) { assert(method_exists($promise, 'always')); }
    if ($promise instanceof CancellablePromiseInterface) { assert(method_exists($promise, 'cancel')); }
    
    // new (single PromiseInterface with all methods)
    assert($promise instanceof PromiseInterface);
    assert(method_exists($promise, 'then'));
    assert(method_exists($promise, 'catch'));
    assert(method_exists($promise, 'finally'));
    assert(method_exists($promise, 'cancel'));
  • Feature / BC break: Improve type safety of promises. Require mixed fulfillment value argument and Throwable (or Exception) as rejection reason.
    Add PHPStan template types to ensure strict types for resolve(T $value): PromiseInterface<T> and reject(Throwable $reason): PromiseInterface<never>.
    It is no longer possible to resolve a promise without a value (use null instead) or reject a promise without a reason (use Throwable instead).
    (#93, #141 and #142 by @jsor, #138, #149 and #247 by @WyriHaximus and #213 and #246 by @clue)

    // old (arguments used to be optional)
    $promise = resolve();
    $promise = reject();
    
    // new (already supported before)
    $promise = resolve(null);
    $promise = reject(new RuntimeException());
  • Feature / BC break: Report all unhandled rejections by default and remove done() method.
    Add new set_rejection_handler() function to set the global rejection handler for unhandled promise rejections.
    (#248, #249 and #224 by @clue)

    // Unhandled promise rejection with RuntimeException: Unhandled in example.php:2
    reject(new RuntimeException('Unhandled'));
  • BC break: Remove all deprecated APIs and reduce API surface.
    Remove some(), map(), reduce() functions, use any() and all() functions instead.
    Remove internal FulfilledPromise and RejectedPromise classes, use resolve() and reject() functions instead.
    Remove legacy promise progress API (deprecated third argument to then() method) and deprecated LazyPromise class.
    (#32 and #98 by @jsor and #164, #219 and #220 by @clue)

  • BC break: Make all classes final to encourage composition over inheritance.
    (#80 by @jsor)

  • Feature / BC break: Require array (or iterable) type for all() + race() + any() functions and bring in line with ES6 specification.
    These functions now require a single argument with a variable number of promises or values as input.
    (#225 by @clue and #35 by @jsor)

  • Fix / BC break: Fix race() to return a forever pending promise when called with an empty array (or iterable) and bring in line with ES6 specification.
    (#83 by @jsor and #225 by @clue)

  • Minor performance improvements by initializing Deferred in the constructor and avoiding call_user_func() calls.
    (#151 by @WyriHaximus and #171 by @Kubo2)

  • Minor documentation improvements.
    (#110 by @seregazhuk, #132 by @CharlotteDunois, #145 by @danielecr, #178 by @WyriHaximus, #189 by @srdante, #212 by @clue, #214, #239 and #243 by @SimonFrings and #231 by @nhedger)

The following changes had to be ported to this release due to our branching
strategy, but also appeared in the 2.x branch:

The following changes were originally planned for this release but later reverted
and are not part of the final release:

  • Add iterative callback queue handler to avoid recursion (later removed to improve Fiber support).
    (#28, #82 and #86 by @jsor, #158 by @WyriHaximus and #229 and #238 by @clue)

  • Trigger an E_USER_ERROR instead of throwing an exception from done() (later removed entire done() method to globally report unhandled rejections).
    (#97 by @jsor and #224 and #248 by @clue)

  • Add type declarations for some() (later removed entire some() function).
    (#172 by @WyriHaximus and #219 by @clue)


2.10.0 (2023-05-02) Release on GitHub


2022

2.9.0 (2022-02-11) Release on GitHub

  • Feature: Support union types and address deprecation of ReflectionType::getClass() (PHP 8+).
    (#198 by @cdosoftei and @SimonFrings)

    $promise->otherwise(function (OverflowException|UnderflowException $e) {
        echo 'Error: ' . $e->getMessage() . PHP_EOL;
    });
  • Feature: Support intersection types (PHP 8.1+).
    (#195 by @bzikarsky)

    $promise->otherwise(function (OverflowException&CacheException $e) {
        echo 'Error: ' . $e->getMessage() . PHP_EOL;
    });
  • Improve test suite, use GitHub actions for continuous integration (CI),
    update to PHPUnit 9, and add full core team to the license.
    (#174, #183, #186, and #201 by @SimonFrings and #211 by @clue)


2020

2.8.0 (2020-05-12) Release on GitHub

  • Mark FulfilledPromise, RejectedPromise and LazyPromise as deprecated for Promise v2 (and remove for Promise v3).
    (#143 and #165 by @clue)

    // deprecated
    $fulfilled = new React\Promise\FulfilledPromise($value);
    $rejected = new React\Promise\RejectedPromise($reason);
    
    // recommended alternatives
    $fulfilled = React\Promise\resolve($value);
    $rejected = React\Promise\reject($reason);
  • Fix: Fix checking whether cancellable promise is an object and avoid possible warning.
    (#168 by @smscr and @jsor)

  • Improve documentation and add docblocks to functions and interfaces.
    (#135 by @CharlotteDunois)

  • Add .gitattributes to exclude dev files from exports.
    (#154 by @reedy)

  • Improve test suite, run tests on PHP 7.4 and update PHPUnit test setup.
    (#163 by @clue)


2019

2.7.1 (2019-01-07) Release on GitHub

  • Fix: file_exists warning when resolving with long strings. (#130 by @sbesselsen)
  • Improve performance by prefixing all global functions calls with \ to skip the look up and resolve process and go straight to the global function. (#133 by @WyriHaximus)

2018

2.7.0 (2018-06-13) Release on GitHub

  • Feature: Improve memory consumption for pending promises by using static internal callbacks without binding to self.
    (#124 by @clue)

2.6.0 (2018-06-11) Release on GitHub

  • Feature: 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)


2017

2.5.1 (2017-03-25) Release on GitHub

  • Fix circular references when resolving with a promise which follows itself (#94).

2016

2.5.0 (2016-12-22) Release on GitHub

  • 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).


2.4.1 (2016-05-03) Release on GitHub

  • Fix some() not cancelling pending promises when too much input promises reject (16ff799).

2.4.0 (2016-03-31) Release on GitHub

  • Support foreign thenables in resolve().
    Any object that provides a then() method is now assimilated to a trusted promise that follows the state of this thenable (#52).
  • Fix some() and any() for input arrays containing not enough items (#34).

2.3.0 (2016-03-24) Release on GitHub

  • Allow cancellation of promises returned by functions working on promise collections (#36).
  • Handle \Throwable in the same way as \Exception (#51 by @joshdifabio).

1.2.1 (2016-03-07) Release on GitHub

  • Fix DeferredPromise to also implement the CancellablePromiseInterface.

1.2.0 (2016-02-27) Release on GitHub

This release makes the API more compatible with 2.0 while preserving full backward compatibility.

  • Introduce new CancellablePromiseInterface implemented by all promises.
  • Add new .cancel() method (part of the CancellablePromiseInterface).

2.2.2 (2016-02-26) Release on GitHub

  • Fix cancellation handlers called multiple times (#47 by @clue).

2015

2.2.1 (2015-07-03) Release on GitHub

  • Fix stack error when resolving a promise in its own fulfillment or rejection handlers.

1.1.0 (2015-07-01) Release on GitHub

This release makes the API more compatible with 2.0 while preserving full backward compatibility.

  • Add React\Promise\Promise class.
  • Move methods of React\Promise\When and React\Promise\Util to functions while keeping the classes as a proxy for BC.

2014

2.2.0 (2014-12-30) Release on GitHub

This release introduces the ExtendedPromiseInterface.

The ExtendedPromiseInterface extends the PromiseInterface with useful shortcut
and utility methods which are not part of the Promises/A specification.


2.1.0 (2014-10-15) Release on GitHub

Introduce new CancellablePromiseInterface implemented by all promises.


2013

2.0.0 (2013-12-10) Release on GitHub

New major release. The goal was to streamline the API and to make it more compliant with other promise libraries and especially with the new upcoming ES6 promises specification.

  • Add standalone Promise class.
  • Add new React\Promise\race() function.
  • BC break: Bump minimum PHP version to PHP 5.4.
  • BC break: Remove ResolverInterface and PromiseInterface from Deferred.
  • BC break: Change signature of PromiseInterface.
  • BC break: Remove When and Util classes and move static methods to functions.
  • BC break: FulfilledPromise and RejectedPromise now throw an exception when initialized with a promise instead of a value/reason.
  • BC break: React\Promise\Deferred::resolve() and React\Promise\Deferred::reject() no longer return a promise.

1.0.4 (2013-04-03) Release on GitHub

  • Trigger PHP errors when invalid callback is passed.
  • Fully resolve rejection value before calling rejection handler.
  • Add When::lazy() to create lazy promises which will be initialized once a consumer calls the then() method.

2012

1.0.3 (2012-11-17) Release on GitHub

  • Add PromisorInterface for objects that have a promise() method.

1.0.2 (2012-11-14) Release on GitHub

  • Fix bug in When::any() not correctly unwrapping to a single result value
  • $promiseOrValue argument of When::resolve() and When::reject() is now optional

1.0.1 (2012-11-13) Release on GitHub

  • Prevent deep recursion which was reaching xdebug.max_nesting_level default of 100

1.0.0 (2012-11-07) Release on GitHub

  • First tagged release