PHPackages                             angegroup/promise - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. angegroup/promise

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

angegroup/promise
=================

Promise is an API developed by AngeGroup. A Promise/A+ inspired implementation in PHP with cancellation support.

v1.0.1(7mo ago)029MITPHPCI failing

Since Nov 13Pushed 1mo agoCompare

[ Source](https://github.com/AngeGroup/Promise)[ Packagist](https://packagist.org/packages/angegroup/promise)[ RSS](/packages/angegroup-promise/feed)WikiDiscussions stable Synced today

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Promise
=======

[](#promise)

[![CI](https://github.com/AngeGroup/Promise/actions/workflows/ci.yml/badge.svg)](https://github.com/AngeGroup/Promise/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A Promise/A+ inspired implementation in PHP, with cooperative cancellation support. Inspired by ReactPHP's promise library.

Installation
------------

[](#installation)

```
composer require angegroup/promise
```

Requires PHP 8.2+.

Quick start
-----------

[](#quick-start)

```
use function promise\resolve;

resolve(42)
    ->then(fn ($v) => $v * 2)
    ->then(function ($v) {
        echo "Got: $v\n"; // 84
    });
```

API
---

[](#api)

### `Promise`

[](#promise-1)

Construct a promise from a resolver callback. The resolver receives `$resolve`and `$reject` and runs synchronously inside the constructor:

```
use promise\Promise;

$promise = new Promise(function ($resolve, $reject) {
    $resolve('value');
    // or $reject(new \RuntimeException('error'));
});
```

Pass an optional second `$canceller` callable that runs when `$promise->cancel()`is called by anyone holding a handle on the promise.

### `Deferred`

[](#deferred)

A handle to externally settle a promise — useful when the resolution comes from an event, a timer, or any caller outside the promise constructor:

```
use promise\Deferred;

$deferred = new Deferred();

// ... later, when something happens:
$deferred->resolve('result');
// or:
$deferred->reject(new \RuntimeException('failure'));

// Hand the promise to consumers:
$deferred->promise()->then(...);
```

### `PromiseInterface`

[](#promiseinterface)

All promises implement:

MethodPurpose`then(?callable $onFulfilled, ?callable $onRejected)`Register handlers; returns a derived promise`catch(callable $onRejected)`Shorthand for `then(null, $onRejected)`. Type-hint the parameter to filter by exception class`finally(callable $onFulfilledOrRejected)`Cleanup callback that runs on either outcome and preserves the original value/reason`cancel()`Cooperative cancellation; calls the canceller registered when the promise was created`wait()`No-op without an underlying event loop. Kept for interface compatibility`isResolved()`True once the promise has settled (either way)### Top-level functions

[](#top-level-functions)

All in the `promise\` namespace.

```
use function promise\{resolve, reject, all, race, any, allSettled};
```

#### `resolve(mixed $value): PromiseInterface`

[](#resolvemixed-value-promiseinterface)

- A `PromiseInterface` is returned as-is.
- A "thenable" object (any object with a `then` method) is adapted into a Promise.
- Anything else becomes a `FulfilledPromise` carrying the value.

#### `reject(Throwable $reason): PromiseInterface`

[](#rejectthrowable-reason-promiseinterface)

Always returns a rejected promise carrying the throwable.

#### `all(iterable $promisesOrValues): PromiseInterface`

[](#alliterable-promisesorvalues-promiseinterface)

Resolves with an array of all values when every input fulfills (preserving keys). Rejects on the first rejection. Resolves with `[]` for an empty iterable.

```
all([resolve(1), resolve(2), 3])->then(fn ($vs) => print_r($vs));
// [1, 2, 3]
```

#### `race(iterable $promisesOrValues): PromiseInterface`

[](#raceiterable-promisesorvalues-promiseinterface)

Settles the same way as the first input that settles (fulfilled or rejected). **Pending forever** when given an empty iterable.

#### `any(iterable $promisesOrValues): PromiseInterface`

[](#anyiterable-promisesorvalues-promiseinterface)

Resolves with the value of the first input to fulfill. Only rejects if **all**inputs reject — the rejection is a `CompositeException` carrying every reason. Rejects with `LengthException` when given an empty iterable.

#### `allSettled(iterable $promisesOrValues): PromiseInterface`

[](#allsettlediterable-promisesorvalues-promiseinterface)

Resolves once every input has settled. The resolution value is an array of result entries (preserving keys):

```
[
    ['status' => 'fulfilled', 'value' => mixed],
    ['status' => 'rejected',  'reason' => Throwable],
]
```

Never short-circuits. Resolves with `[]` for an empty iterable.

### Typed catch

[](#typed-catch)

`catch()` inspects the rejection handler's first parameter type. If the rejection reason isn't an instance of that type, the handler is skipped and the rejection propagates to the next handler:

```
$promise
    ->catch(function (NotFoundException $e) {
        // only catches NotFoundException
    })
    ->catch(function (\Throwable $e) {
        // catches everything else
    });
```

Union and intersection types are supported.

Exceptions
----------

[](#exceptions)

ClassThrown by`promise\exception\CompositeException``any()` when every input rejects. `getThrowables()` returns the per-input reasons.`promise\exception\LengthException``any()` when given an empty iterable.`promise\exception\TimeoutException`Reserved for `wait()` implementations backed by an event loop.Development
-----------

[](#development)

```
composer install
composer test            # PHPUnit
composer test-coverage   # PHPUnit with coverage summary
composer cs-check        # php-cs-fixer dry-run
composer cs-fix          # apply formatting
composer phpstan         # static analysis
```

CI runs validate, syntax, php-cs-fixer (dry-run), PHPStan level 8 and PHPUnit as five parallel jobs on every push and pull request.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance79

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

2

Last Release

216d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/61889427?v=4)[Dumont-Julien](/maintainers/Dumont-Julien)[@Dumont-Julien](https://github.com/Dumont-Julien)

---

Top Contributors

[![Dumont-Julien](https://avatars.githubusercontent.com/u/61889427?v=4)](https://github.com/Dumont-Julien "Dumont-Julien (4 commits)")

### Embed Badge

![Health badge](/badges/angegroup-promise/health.svg)

```
[![Health](https://phpackages.com/badges/angegroup-promise/health.svg)](https://phpackages.com/packages/angegroup-promise)
```

###  Alternatives

[mouf/nodejs-installer

An installer package that let's you install NodeJS and NPM as a Composer dependency.

107709.1k15](/packages/mouf-nodejs-installer)[gerardojbaez/messenger

Messenger functionality for Laravel 5.2.

738.5k](/packages/gerardojbaez-messenger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
