ahmard / simple-promise
A simple PHP promise library that works synchronously.
1.0.0
2020-07-26 17:44 UTC
Requires
- php: ^7.4
This package is auto-updated.
Last update: 2024-10-27 03:31:48 UTC
README
A simple PHP promise library that works synchronously.
Note
Please note that this library cannot be used in Asynchronous projects, projects like ReactPHP or Amphp.
Installation
Make sure that you have composer installed Composer.
If you don't have Composer run the below command
curl -sS https://getcomposer.org/installer | php
Run the installation
composer require ahmard/simple-promise ^1.0
Usage
<?php use SimplePromise\Deferred; require 'vendor/autoload.php'; function test($number) { $deferred = new Deferred(); if ($number > 2){ $deferred->resolve('Succeeded'); }else{ $deferred->reject('Failed'); } return $deferred->promise(); } test(1)->then(function ($data){ echo $data; })->otherwise(function ($error){ echo $error; });