PHPackages                             onion/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. onion/promise

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

onion/promise
=============

1.0.0(7y ago)2301[1 PRs](https://github.com/phOnion/promise/pulls)1MITPHP

Since Jan 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/phOnion/promise)[ Packagist](https://packagist.org/packages/onion/promise)[ RSS](/packages/onion-promise/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (1)

Introduction
============

[](#introduction)

[![Build Status](https://camo.githubusercontent.com/206469eae118fbd2f3fca36284fadb12803c8996daf7c94ea682f719744e7a48/68747470733a2f2f7472617669732d63692e6f72672f70684f6e696f6e2f70726f6d6973652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phOnion/promise)[![Mutation testing badge](https://camo.githubusercontent.com/d51f430ca3a5eff67f1690396bd9b8206d29d34690b152ba4b087c4408d2eec8/68747470733a2f2f62616467652e737472796b65722d6d757461746f722e696f2f6769746875622e636f6d2f70684f6e696f6e2f70726f6d6973652f6d6173746572)](https://infection.github.io)

---

This is an [Promises/A+](https://promisesaplus.com/) implementation that should be fully compatible with any already existing implementations without any 3rd party dependencies.

This package defines 2 interfaces `PromiseInterface` &amp; `ThenableInterface` as per the spec also there are some helper functions as well as some that provide a more sugary feel to the code.

`is_thenable` - Function that checks if an object is "thenable" `coroutine` - Push a task as a promise. This one changes it's implementation depending on whether or not the `swoole` extension is available on the server. If it is then the native coroutines available as `go` function are used, alternatively it falls back to an approach similar to an event loop.

A tick function is registered using `register_tick_function` that will invoke 1 task per so that not to bring your application to a complete halt when executing. As well as there is a function registered for shutdown that will run all remaining tasks in a blocking way until the queue is empty - albeit hanging the request.

For when the synchronous mode is used, you should do `declare(ticks=1)` see [the PHP Docs](https://secure.php.net/manual/en/control-structures.declare.php#control-structures.declare.ticks)

***NOTE**: Please, keep in mind that your code will block until the task is processed so this 'mode' is not recommended and users should look at alternative approaches for their heavy tasks or install `swoole`*

`async` - alias for `coroutine`, intended to mimic the `async` keyword in JS/TS/C#

==============

Usage
-----

[](#usage)

```
use \Onion\Framework\Promise\async;

$promise = async(function () use ($orm, $id, $password) {
    $user = $orm->findById($id); // if it throws any exception the promise will immediately get rejected

    if (!$user->isActive()) {
        throw new \RuntimeException('User is not activated yet');
    }

    if (!password_verify($password, $user->getPassword())) {
        throw new \InvalidArgumentException('Invalid password provided');
    }

    return $user;
})->then(function (User $user) use ($paymentService) {
    $paymentService->processUserPayment($user->getId());
    echo "User {$user->getId()} processed successfully";
}, function (\Throwable $ex) {
    echo "Ops.. {$ex->getMessage()}";
})->otherwise(function (\Throwable $ex) {
    // Do something else with the exception maybe ?
})->finally(function () use ($orm) {
    // Regardless of the state change, but it is always called at the end of execution
    $orm->disconnect();
});
```

The function passed to `async`/`coroutine` will be executed immediately so do keep in mind that when using without `swoole`.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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

Unknown

Total

1

Last Release

2675d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebe6247144a757a92ffa4f6844481b44b2c3be096076560e14a14e89053719b5?d=identicon)[DaGhostman](/maintainers/DaGhostman)

---

Top Contributors

[![DaGhostman](https://avatars.githubusercontent.com/u/2286949?v=4)](https://github.com/DaGhostman "DaGhostman (95 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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