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

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

dface/promise
=============

Implementation of CommonJS Promises/A pattern for PHP.

253PHP

Since Feb 10Pushed 12y ago1 watchersCompare

[ Source](https://github.com/3DFace/promise)[ Packagist](https://packagist.org/packages/dface/promise)[ RSS](/packages/dface-promise/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

dface/promise
=============

[](#dfacepromise)

Yet another implementation of CommonJS [Promises/A](http://wiki.commonjs.org/wiki/Promises/A) pattern for PHP.

Initial purpose of the project was to clarify `Promises` pattern in my head. After implementing it I found it quite lightweight and clean. So I decided to share.

About `on_progress`.

At first I tried to implement it. But for now I believe that this feature does not fit into the idea of the pattern. In my opinion, `Promises` was intended to organize a flow control. While `on_progress` appears to solve application specific problems. So I rejected it.

Setup
-----

[](#setup)

Add to your composer.json file:

```
{
	"require": {
		"dface/promise": "dev-master"
	}
}
```

Library organized according to PSR-0.

So you can use composer autoloader:

```
require 'vendor/autoload.php';
```

or use custom PSR-0 loader.

Most of the package will work with PHP 5.4, but if you want to use `Flow` you have to switch to &gt;=5.5 to make generators available.

Usage
-----

[](#usage)

I will not explain the concept of the promises here. I will assume that you are already familiar with them.

```
require 'vendor/autoload.php';

use dface\promise\Deferred;

$x = new Deferred();

$x->then(function($val){
    echo "fulfilled: $val\n";
})->trap(function($e){
    echo "rejected: $e\n";
})->end(function(){
    echo "finished\n";
});

$x->fulfill(1);
```

You can see that in addition to the classical `then` there are two 'sugar' methods - `trap` to catch rejects, and `end` to make finalization.

You will find standard set of promises in this package: `Fulfilled`, `Rejected`, `Deferred`, `All`, `Some`, `Race` and `Flow`.

I'd like to show you a fabricated example of `Flow` promise.

```
$x = new Flow(function () {
	$v1 = (yield promiseProducer1());
	$v2 = (yield promiseProducer2());
	$v3 = (yield promiseProducer3($v1, $v2));
	yield $v3;
});
```

`Flow` promise works like an envelope for its 'flow function'. In that function you can use special syntax to work with promises. Instead of chaining promises with `then` you can describe execution flow in a straightforward manner just like you do in a synchronous world. All you have to do is to preface your promises with `yield` keyword. `Flow` will make the rest behind the scene.

```
$x = new Flow(function () {
	$v1 = (yield promiseProducer1());
	try{
		$v2 = (yield promiseProducer2($v1));
	}catch(Exception $e){
		$v2 = (yield promiseProducer3($v1));
	}
	yield $v2;
});
```

You can see that you can `catch` rejected promises with `try...catch` constructions.

Tests
-----

[](#tests)

```
phpunit --bootstrap tests/bootstrap.php tests/

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/faaef133956fbef7d0c35eb2b65aafd88e741240c11b6f55b7d5fda04125c0cf?d=identicon)[3DFace](/maintainers/3DFace)

---

Top Contributors

[![3DFace](https://avatars.githubusercontent.com/u/1931471?v=4)](https://github.com/3DFace "3DFace (8 commits)")

### Embed Badge

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

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

###  Alternatives

[ichtrojan/laravel-location

2102.9k](/packages/ichtrojan-laravel-location)[spirit55555/php-minecraft

Useful PHP classes for Minecraft

6823.6k](/packages/spirit55555-php-minecraft)

PHPackages © 2026

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