https://github.com/activecollab/promises
https://github.com/activecollab/promises
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/activecollab/promises
- Owner: activecollab
- License: mit
- Created: 2016-01-29T19:17:40.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-03-03T09:04:16.000Z (over 4 years ago)
- Last Synced: 2025-03-30T13:03:29.017Z (about 1 year ago)
- Language: PHP
- Size: 55.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Promises Library
[](https://travis-ci.org/activecollab/promises)
Purpose of this library is to provide persisted server side promises. We built it to power our multi-service system, where one service issues a job requests and expect that antoher service executes it (and fulfulls or rejects a promise that it gives when it accepts a job).
Example:
```php
connect_error) {
throw new \RuntimeException('Failed to connect to database. MySQL said: ' . $mysqli_link->connect_error);
}
$mysqli_connection = new MysqliConnection($mysqli_link);
$promises = new Promises($this->connection);
// Print promise signature
$promise = $promises->create();
print $promise->getSinature() . "\n";
print (string) $promise . "\n"; // __toString() is available
// Default promise status
$promise = $promises->create();
$promises->isFulfilled($promise); // false
$promises->isRejected($promise); // false
$promises->isSettled($promise); // false
// Promise fulfillment
$promise = $promises->create();
$promises->fulfill($promise);
$promises->isFulfilled($promise); // true
$promises->isRejected($promise); // false
$promises->isSettled($promise); // true
// Promise rejection
$promise = $promises->create();
$promises->reject($promise);
$promises->isFulfilled($promise); // false
$promises->isRejected($promise); // true
$promises->isSettled($promise); // true
```
## Running tests
To run tests, `cd` to this directory and run:
```bash
phpunit -c test
```