{"id":13660389,"url":"https://github.com/reactphp/promise","last_synced_at":"2025-05-14T08:05:04.040Z","repository":{"id":5202609,"uuid":"6378047","full_name":"reactphp/promise","owner":"reactphp","description":"Promises/A implementation for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-19T18:32:50.000Z","size":826,"stargazers_count":2424,"open_issues_count":2,"forks_count":148,"subscribers_count":51,"default_branch":"3.x","last_synced_at":"2025-05-07T07:08:49.393Z","etag":null,"topics":["php","promise","reactphp"],"latest_commit_sha":null,"homepage":"https://reactphp.org/promise/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reactphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["reactphp","clue","WyriHaximus"],"open_collective":"reactphp"}},"created_at":"2012-10-24T21:41:22.000Z","updated_at":"2025-05-01T19:56:30.000Z","dependencies_parsed_at":"2023-12-19T04:22:55.545Z","dependency_job_id":"75129929-04fa-421c-8f49-074f6ac80c44","html_url":"https://github.com/reactphp/promise","commit_stats":{"total_commits":405,"total_committers":30,"mean_commits":13.5,"dds":0.3481481481481481,"last_synced_commit":"8a164643313c71354582dc850b42b33fa12a4b63"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fpromise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fpromise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fpromise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fpromise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactphp","download_url":"https://codeload.github.com/reactphp/promise/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254070141,"owners_count":22009560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","promise","reactphp"],"created_at":"2024-08-02T05:01:21.012Z","updated_at":"2025-05-14T08:05:03.993Z","avatar_url":"https://github.com/reactphp.png","language":"PHP","funding_links":["https://github.com/sponsors/reactphp","https://github.com/sponsors/clue","https://github.com/sponsors/WyriHaximus","https://opencollective.com/reactphp"],"categories":["PHP","类库"],"sub_categories":["异步/协程"],"readme":"Promise\n=======\n\nA lightweight implementation of\n[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.\n\n[![CI status](https://github.com/reactphp/promise/workflows/CI/badge.svg)](https://github.com/reactphp/promise/actions)\n[![installs on Packagist](https://img.shields.io/packagist/dt/react/promise?color=blue\u0026label=installs%20on%20Packagist)](https://packagist.org/packages/react/promise)\n\nTable of Contents\n-----------------\n\n1. [Introduction](#introduction)\n2. [Concepts](#concepts)\n   * [Deferred](#deferred)\n   * [Promise](#promise-1)\n3. [API](#api)\n   * [Deferred](#deferred-1)\n     * [Deferred::promise()](#deferredpromise)\n     * [Deferred::resolve()](#deferredresolve)\n     * [Deferred::reject()](#deferredreject)\n   * [PromiseInterface](#promiseinterface)\n     * [PromiseInterface::then()](#promiseinterfacethen)\n     * [PromiseInterface::catch()](#promiseinterfacecatch)\n     * [PromiseInterface::finally()](#promiseinterfacefinally)\n     * [PromiseInterface::cancel()](#promiseinterfacecancel)\n     * [~~PromiseInterface::otherwise()~~](#promiseinterfaceotherwise)\n     * [~~PromiseInterface::always()~~](#promiseinterfacealways)\n   * [Promise](#promise-2)\n   * [Functions](#functions)\n     * [resolve()](#resolve)\n     * [reject()](#reject)\n     * [all()](#all)\n     * [race()](#race)\n     * [any()](#any)\n     * [set_rejection_handler()](#set_rejection_handler)\n4. [Examples](#examples)\n   * [How to use Deferred](#how-to-use-deferred)\n   * [How promise forwarding works](#how-promise-forwarding-works)\n     * [Resolution forwarding](#resolution-forwarding)\n     * [Rejection forwarding](#rejection-forwarding)\n     * [Mixed resolution and rejection forwarding](#mixed-resolution-and-rejection-forwarding)\n5. [Install](#install)\n6. [Tests](#tests)\n7. [Credits](#credits)\n8. [License](#license)\n\nIntroduction\n------------\n\nPromise is a library implementing\n[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.\n\nIt also provides several other useful promise-related concepts, such as joining\nmultiple promises and mapping and reducing collections of promises.\n\nIf you've never heard about promises before,\n[read this first](https://gist.github.com/domenic/3889970).\n\nConcepts\n--------\n\n### Deferred\n\nA **Deferred** represents a computation or unit of work that may not have\ncompleted yet. Typically (but not always), that computation will be something\nthat executes asynchronously and completes at some point in the future.\n\n### Promise\n\nWhile a deferred represents the computation itself, a **Promise** represents\nthe result of that computation. Thus, each deferred has a promise that acts as\na placeholder for its actual result.\n\nAPI\n---\n\n### Deferred\n\nA deferred represents an operation whose resolution is pending. It has separate\npromise and resolver parts.\n\n```php\n$deferred = new React\\Promise\\Deferred();\n\n$promise = $deferred-\u003epromise();\n\n$deferred-\u003eresolve(mixed $value);\n$deferred-\u003ereject(\\Throwable $reason);\n```\n\nThe `promise` method returns the promise of the deferred.\n\nThe `resolve` and `reject` methods control the state of the deferred.\n\nThe constructor of the `Deferred` accepts an optional `$canceller` argument.\nSee [Promise](#promise-2) for more information.\n\n#### Deferred::promise()\n\n```php\n$promise = $deferred-\u003epromise();\n```\n\nReturns the promise of the deferred, which you can hand out to others while\nkeeping the authority to modify its state to yourself.\n\n#### Deferred::resolve()\n\n```php\n$deferred-\u003eresolve(mixed $value);\n```\n\nResolves the promise returned by `promise()`. All consumers are notified by\nhaving `$onFulfilled` (which they registered via `$promise-\u003ethen()`) called with\n`$value`.\n\nIf `$value` itself is a promise, the promise will transition to the state of\nthis promise once it is resolved.\n\nSee also the [`resolve()` function](#resolve).\n\n#### Deferred::reject()\n\n```php\n$deferred-\u003ereject(\\Throwable $reason);\n```\n\nRejects the promise returned by `promise()`, signalling that the deferred's\ncomputation failed.\nAll consumers are notified by having `$onRejected` (which they registered via\n`$promise-\u003ethen()`) called with `$reason`.\n\nSee also the [`reject()` function](#reject).\n\n### PromiseInterface\n\nThe promise interface provides the common interface for all promise\nimplementations.\nSee [Promise](#promise-2) for the only public implementation exposed by this\npackage.\n\nA promise represents an eventual outcome, which is either fulfillment (success)\nand an associated value, or rejection (failure) and an associated reason.\n\nOnce in the fulfilled or rejected state, a promise becomes immutable.\nNeither its state nor its result (or error) can be modified.\n\n#### PromiseInterface::then()\n\n```php\n$transformedPromise = $promise-\u003ethen(callable $onFulfilled = null, callable $onRejected = null);\n```\n\nTransforms a promise's value by applying a function to the promise's fulfillment\nor rejection value. Returns a new promise for the transformed result.\n\nThe `then()` method registers new fulfilled and rejection handlers with a promise\n(all parameters are optional):\n\n  * `$onFulfilled` will be invoked once the promise is fulfilled and passed\n    the result as the first argument.\n  * `$onRejected` will be invoked once the promise is rejected and passed the\n    reason as the first argument.\n\nIt returns a new promise that will fulfill with the return value of either\n`$onFulfilled` or `$onRejected`, whichever is called, or will reject with\nthe thrown exception if either throws.\n\nA promise makes the following guarantees about handlers registered in\nthe same call to `then()`:\n\n  1. Only one of `$onFulfilled` or `$onRejected` will be called,\n     never both.\n  2. `$onFulfilled` and `$onRejected` will never be called more\n     than once.\n\n#### See also\n\n* [resolve()](#resolve) - Creating a resolved promise\n* [reject()](#reject) - Creating a rejected promise\n\n#### PromiseInterface::catch()\n\n```php\n$promise-\u003ecatch(callable $onRejected);\n```\n\nRegisters a rejection handler for promise. It is a shortcut for:\n\n```php\n$promise-\u003ethen(null, $onRejected);\n```\n\nAdditionally, you can type hint the `$reason` argument of `$onRejected` to catch\nonly specific errors.\n\n```php\n$promise\n    -\u003ecatch(function (\\RuntimeException $reason) {\n        // Only catch \\RuntimeException instances\n        // All other types of errors will propagate automatically\n    })\n    -\u003ecatch(function (\\Throwable $reason) {\n        // Catch other errors\n    });\n```\n\n#### PromiseInterface::finally()\n\n```php\n$newPromise = $promise-\u003efinally(callable $onFulfilledOrRejected);\n```\n\nAllows you to execute \"cleanup\" type tasks in a promise chain.\n\nIt arranges for `$onFulfilledOrRejected` to be called, with no arguments,\nwhen the promise is either fulfilled or rejected.\n\n* If `$promise` fulfills, and `$onFulfilledOrRejected` returns successfully,\n  `$newPromise` will fulfill with the same value as `$promise`.\n* If `$promise` fulfills, and `$onFulfilledOrRejected` throws or returns a\n  rejected promise, `$newPromise` will reject with the thrown exception or\n  rejected promise's reason.\n* If `$promise` rejects, and `$onFulfilledOrRejected` returns successfully,\n  `$newPromise` will reject with the same reason as `$promise`.\n* If `$promise` rejects, and `$onFulfilledOrRejected` throws or returns a\n  rejected promise, `$newPromise` will reject with the thrown exception or\n  rejected promise's reason.\n\n`finally()` behaves similarly to the synchronous finally statement. When combined\nwith `catch()`, `finally()` allows you to write code that is similar to the familiar\nsynchronous catch/finally pair.\n\nConsider the following synchronous code:\n\n```php\ntry {\n    return doSomething();\n} catch (\\Throwable $e) {\n    return handleError($e);\n} finally {\n    cleanup();\n}\n```\n\nSimilar asynchronous code (with `doSomething()` that returns a promise) can be\nwritten:\n\n```php\nreturn doSomething()\n    -\u003ecatch('handleError')\n    -\u003efinally('cleanup');\n```\n\n#### PromiseInterface::cancel()\n\n``` php\n$promise-\u003ecancel();\n```\n\nThe `cancel()` method notifies the creator of the promise that there is no\nfurther interest in the results of the operation.\n\nOnce a promise is settled (either fulfilled or rejected), calling `cancel()` on\na promise has no effect.\n\n#### ~~PromiseInterface::otherwise()~~\n\n\u003e Deprecated since v3.0.0, see [`catch()`](#promiseinterfacecatch) instead.\n\nThe `otherwise()` method registers a rejection handler for a promise.\n\nThis method continues to exist only for BC reasons and to ease upgrading\nbetween versions. It is an alias for:\n\n```php\n$promise-\u003ecatch($onRejected);\n```\n\n#### ~~PromiseInterface::always()~~\n\n\u003e Deprecated since v3.0.0, see [`finally()`](#promiseinterfacefinally) instead.\n\nThe `always()` method allows you to execute \"cleanup\" type tasks in a promise chain.\n\nThis method continues to exist only for BC reasons and to ease upgrading\nbetween versions. It is an alias for:\n\n```php\n$promise-\u003efinally($onFulfilledOrRejected);\n```\n\n### Promise\n\nCreates a promise whose state is controlled by the functions passed to\n`$resolver`.\n\n```php\n$resolver = function (callable $resolve, callable $reject) {\n    // Do some work, possibly asynchronously, and then\n    // resolve or reject.\n\n    $resolve($awesomeResult);\n    // or throw new Exception('Promise rejected');\n    // or $resolve($anotherPromise);\n    // or $reject($nastyError);\n};\n\n$canceller = function () {\n    // Cancel/abort any running operations like network connections, streams etc.\n\n    // Reject promise by throwing an exception\n    throw new Exception('Promise cancelled');\n};\n\n$promise = new React\\Promise\\Promise($resolver, $canceller);\n```\n\nThe promise constructor receives a resolver function and an optional canceller\nfunction which both will be called with two arguments:\n\n  * `$resolve($value)` - Primary function that seals the fate of the\n    returned promise. Accepts either a non-promise value, or another promise.\n    When called with a non-promise value, fulfills promise with that value.\n    When called with another promise, e.g. `$resolve($otherPromise)`, promise's\n    fate will be equivalent to that of `$otherPromise`.\n  * `$reject($reason)` - Function that rejects the promise. It is recommended to\n    just throw an exception instead of using `$reject()`.\n\nIf the resolver or canceller throw an exception, the promise will be rejected\nwith that thrown exception as the rejection reason.\n\nThe resolver function will be called immediately, the canceller function only\nonce all consumers called the `cancel()` method of the promise.\n\n### Functions\n\nUseful functions for creating and joining collections of promises.\n\nAll functions working on promise collections (like `all()`, `race()`,\netc.) support cancellation. This means, if you call `cancel()` on the returned\npromise, all promises in the collection are cancelled.\n\n#### resolve()\n\n```php\n$promise = React\\Promise\\resolve(mixed $promiseOrValue);\n```\n\nCreates a promise for the supplied `$promiseOrValue`.\n\nIf `$promiseOrValue` is a value, it will be the resolution value of the\nreturned promise.\n\nIf `$promiseOrValue` is a thenable (any object that provides a `then()` method),\na trusted promise that follows the state of the thenable is returned.\n\nIf `$promiseOrValue` is a promise, it will be returned as is.\n\nThe resulting `$promise` implements the [`PromiseInterface`](#promiseinterface)\nand can be consumed like any other promise:\n\n```php\n$promise = React\\Promise\\resolve(42);\n\n$promise-\u003ethen(function (int $result): void {\n    var_dump($result);\n}, function (\\Throwable $e): void {\n    echo 'Error: ' . $e-\u003egetMessage() . PHP_EOL;\n});\n```\n\n#### reject()\n\n```php\n$promise = React\\Promise\\reject(\\Throwable $reason);\n```\n\nCreates a rejected promise for the supplied `$reason`.\n\nNote that the [`\\Throwable`](https://www.php.net/manual/en/class.throwable.php) interface introduced in PHP 7 covers \nboth user land [`\\Exception`](https://www.php.net/manual/en/class.exception.php)'s and \n[`\\Error`](https://www.php.net/manual/en/class.error.php) internal PHP errors. By enforcing `\\Throwable` as reason to \nreject a promise, any language error or user land exception can be used to reject a promise.\n\nThe resulting `$promise` implements the [`PromiseInterface`](#promiseinterface)\nand can be consumed like any other promise:\n\n```php\n$promise = React\\Promise\\reject(new RuntimeException('Request failed'));\n\n$promise-\u003ethen(function (int $result): void {\n    var_dump($result);\n}, function (\\Throwable $e): void {\n    echo 'Error: ' . $e-\u003egetMessage() . PHP_EOL;\n});\n```\n\nNote that rejected promises should always be handled similar to how any\nexceptions should always be caught in a `try` + `catch` block. If you remove the\nlast reference to a rejected promise that has not been handled, it will\nreport an unhandled promise rejection:\n\n```php\nfunction incorrect(): int\n{\n     $promise = React\\Promise\\reject(new RuntimeException('Request failed'));\n\n     // Commented out: No rejection handler registered here.\n     // $promise-\u003ethen(null, function (\\Throwable $e): void { /* ignore */ });\n\n     // Returning from a function will remove all local variable references, hence why\n     // this will report an unhandled promise rejection here.\n     return 42;\n}\n\n// Calling this function will log an error message plus its stack trace:\n// Unhandled promise rejection with RuntimeException: Request failed in example.php:10\nincorrect();\n```\n\nA rejected promise will be considered \"handled\" if you catch the rejection\nreason with either the [`then()` method](#promiseinterfacethen), the\n[`catch()` method](#promiseinterfacecatch), or the\n[`finally()` method](#promiseinterfacefinally). Note that each of these methods\nreturn a new promise that may again be rejected if you re-throw an exception.\n\nA rejected promise will also be considered \"handled\" if you abort the operation\nwith the [`cancel()` method](#promiseinterfacecancel) (which in turn would\nusually reject the promise if it is still pending).\n\nSee also the [`set_rejection_handler()` function](#set_rejection_handler).\n\n#### all()\n\n```php\n$promise = React\\Promise\\all(iterable $promisesOrValues);\n```\n\nReturns a promise that will resolve only once all the items in\n`$promisesOrValues` have resolved. The resolution value of the returned promise\nwill be an array containing the resolution values of each of the items in\n`$promisesOrValues`.\n\n#### race()\n\n```php\n$promise = React\\Promise\\race(iterable $promisesOrValues);\n```\n\nInitiates a competitive race that allows one winner. Returns a promise which is\nresolved in the same way the first settled promise resolves.\n\nThe returned promise will become **infinitely pending** if  `$promisesOrValues`\ncontains 0 items.\n\n#### any()\n\n```php\n$promise = React\\Promise\\any(iterable $promisesOrValues);\n```\n\nReturns a promise that will resolve when any one of the items in\n`$promisesOrValues` resolves. The resolution value of the returned promise\nwill be the resolution value of the triggering item.\n\nThe returned promise will only reject if *all* items in `$promisesOrValues` are\nrejected. The rejection value will be a `React\\Promise\\Exception\\CompositeException`\nwhich holds all rejection reasons. The rejection reasons can be obtained with\n`CompositeException::getThrowables()`.\n\nThe returned promise will also reject with a `React\\Promise\\Exception\\LengthException`\nif `$promisesOrValues` contains 0 items.\n\n#### set_rejection_handler()\n\n```php\nReact\\Promise\\set_rejection_handler(?callable $callback): ?callable;\n```\n\nSets the global rejection handler for unhandled promise rejections.\n\nNote that rejected promises should always be handled similar to how any\nexceptions should always be caught in a `try` + `catch` block. If you remove\nthe last reference to a rejected promise that has not been handled, it will\nreport an unhandled promise rejection. See also the [`reject()` function](#reject)\nfor more details.\n\nThe `?callable $callback` argument MUST be a valid callback function that\naccepts a single `Throwable` argument or a `null` value to restore the\ndefault promise rejection handler. The return value of the callback function\nwill be ignored and has no effect, so you SHOULD return a `void` value. The\ncallback function MUST NOT throw or the program will be terminated with a\nfatal error.\n\nThe function returns the previous rejection handler or `null` if using the\ndefault promise rejection handler.\n\nThe default promise rejection handler will log an error message plus its stack\ntrace:\n\n```php\n// Unhandled promise rejection with RuntimeException: Unhandled in example.php:2\nReact\\Promise\\reject(new RuntimeException('Unhandled'));\n```\n\nThe promise rejection handler may be used to use customize the log message or\nwrite to custom log targets. As a rule of thumb, this function should only be\nused as a last resort and promise rejections are best handled with either the\n[`then()` method](#promiseinterfacethen), the\n[`catch()` method](#promiseinterfacecatch), or the\n[`finally()` method](#promiseinterfacefinally).\nSee also the [`reject()` function](#reject) for more details.\n\nExamples\n--------\n\n### How to use Deferred\n\n```php\nfunction getAwesomeResultPromise()\n{\n    $deferred = new React\\Promise\\Deferred();\n\n    // Execute a Node.js-style function using the callback pattern\n    computeAwesomeResultAsynchronously(function (\\Throwable $error, $result) use ($deferred) {\n        if ($error) {\n            $deferred-\u003ereject($error);\n        } else {\n            $deferred-\u003eresolve($result);\n        }\n    });\n\n    // Return the promise\n    return $deferred-\u003epromise();\n}\n\ngetAwesomeResultPromise()\n    -\u003ethen(\n        function ($value) {\n            // Deferred resolved, do something with $value\n        },\n        function (\\Throwable $reason) {\n            // Deferred rejected, do something with $reason\n        }\n    );\n```\n\n### How promise forwarding works\n\nA few simple examples to show how the mechanics of Promises/A forwarding works.\nThese examples are contrived, of course, and in real usage, promise chains will\ntypically be spread across several function calls, or even several levels of\nyour application architecture.\n\n#### Resolution forwarding\n\nResolved promises forward resolution values to the next promise.\nThe first promise, `$deferred-\u003epromise()`, will resolve with the value passed\nto `$deferred-\u003eresolve()` below.\n\nEach call to `then()` returns a new promise that will resolve with the return\nvalue of the previous handler. This creates a promise \"pipeline\".\n\n```php\n$deferred = new React\\Promise\\Deferred();\n\n$deferred-\u003epromise()\n    -\u003ethen(function ($x) {\n        // $x will be the value passed to $deferred-\u003eresolve() below\n        // and returns a *new promise* for $x + 1\n        return $x + 1;\n    })\n    -\u003ethen(function ($x) {\n        // $x === 2\n        // This handler receives the return value of the\n        // previous handler.\n        return $x + 1;\n    })\n    -\u003ethen(function ($x) {\n        // $x === 3\n        // This handler receives the return value of the\n        // previous handler.\n        return $x + 1;\n    })\n    -\u003ethen(function ($x) {\n        // $x === 4\n        // This handler receives the return value of the\n        // previous handler.\n        echo 'Resolve ' . $x;\n    });\n\n$deferred-\u003eresolve(1); // Prints \"Resolve 4\"\n```\n\n#### Rejection forwarding\n\nRejected promises behave similarly, and also work similarly to try/catch:\nWhen you catch an exception, you must rethrow for it to propagate.\n\nSimilarly, when you handle a rejected promise, to propagate the rejection,\n\"rethrow\" it by either returning a rejected promise, or actually throwing\n(since promise translates thrown exceptions into rejections)\n\n```php\n$deferred = new React\\Promise\\Deferred();\n\n$deferred-\u003epromise()\n    -\u003ethen(function ($x) {\n        throw new \\Exception($x + 1);\n    })\n    -\u003ecatch(function (\\Exception $x) {\n        // Propagate the rejection\n        throw $x;\n    })\n    -\u003ecatch(function (\\Exception $x) {\n        // Can also propagate by returning another rejection\n        return React\\Promise\\reject(\n            new \\Exception($x-\u003egetMessage() + 1)\n        );\n    })\n    -\u003ecatch(function ($x) {\n        echo 'Reject ' . $x-\u003egetMessage(); // 3\n    });\n\n$deferred-\u003eresolve(1);  // Prints \"Reject 3\"\n```\n\n#### Mixed resolution and rejection forwarding\n\nJust like try/catch, you can choose to propagate or not. Mixing resolutions and\nrejections will still forward handler results in a predictable way.\n\n```php\n$deferred = new React\\Promise\\Deferred();\n\n$deferred-\u003epromise()\n    -\u003ethen(function ($x) {\n        return $x + 1;\n    })\n    -\u003ethen(function ($x) {\n        throw new \\Exception($x + 1);\n    })\n    -\u003ecatch(function (\\Exception $x) {\n        // Handle the rejection, and don't propagate.\n        // This is like catch without a rethrow\n        return $x-\u003egetMessage() + 1;\n    })\n    -\u003ethen(function ($x) {\n        echo 'Mixed ' . $x; // 4\n    });\n\n$deferred-\u003eresolve(1);  // Prints \"Mixed 4\"\n```\n\nInstall\n-------\n\nThe recommended way to install this library is [through Composer](https://getcomposer.org/).\n[New to Composer?](https://getcomposer.org/doc/00-intro.md)\n\nThis project follows [SemVer](https://semver.org/).\nThis will install the latest supported version from this branch:\n\n```bash\ncomposer require react/promise:^3.2\n```\n\nSee also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.\n\nThis project aims to run on any platform and thus does not require any PHP\nextensions and supports running on PHP 7.1 through current PHP 8+.\nIt's *highly recommended to use the latest supported PHP version* for this project.\n\nWe're committed to providing long-term support (LTS) options and to provide a\nsmooth upgrade path. If you're using an older PHP version, you may use the\n[`2.x` branch](https://github.com/reactphp/promise/tree/2.x) (PHP 5.4+) or\n[`1.x` branch](https://github.com/reactphp/promise/tree/1.x) (PHP 5.3+) which both\nprovide a compatible API but do not take advantage of newer language features.\nYou may target multiple versions at the same time to support a wider range of\nPHP versions like this:\n\n```bash\ncomposer require \"react/promise:^3 || ^2 || ^1\"\n```\n\n## Tests\n\nTo run the test suite, you first need to clone this repo and then install all\ndependencies [through Composer](https://getcomposer.org/):\n\n```bash\ncomposer install\n```\n\nTo run the test suite, go to the project root and run:\n\n```bash\nvendor/bin/phpunit\n```\n\nOn top of this, we use PHPStan on max level to ensure type safety across the project:\n\n```bash\nvendor/bin/phpstan\n```\n\nCredits\n-------\n\nPromise is a port of [when.js](https://github.com/cujojs/when)\nby [Brian Cavalier](https://github.com/briancavalier).\n\nAlso, large parts of the documentation have been ported from the when.js\n[Wiki](https://github.com/cujojs/when/wiki) and the\n[API docs](https://github.com/cujojs/when/blob/master/docs/api.md).\n\nLicense\n-------\n\nReleased under the [MIT](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactphp%2Fpromise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactphp%2Fpromise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactphp%2Fpromise/lists"}