Skip to content

The PHP Promise handling PHP promises with additional utilities and features.

License

Notifications You must be signed in to change notification settings

lazervel/promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Promise

Promise

Total Downloads Latest Version

Composer Installation

Installation is super-easy via Composer

composer require modassir/promise

or add it by hand to your composer.json file.

Getting Started

use Modassir\Promise\Promise;

(new Promise(function($resolve, $reject) {
  $resolve('success');
  $reject('An error accurred.');
}))->then(function($res) {
  // echo : 'success'
})->catch(function() {

})->finally(function() {
  // echo: strtoupper('Hello Worlds!');
});

(new Promise(function($resolve, $reject) {
  $reject('An error accurred.');
  $resolve('success');
}))->then(function() {

})->catch(function($res) {
  // echo: 'An error accurred.'
})->finally(function() {
  // echo: strtoupper('Hello Worlds!');
});

(new Promise(function($resolve, $reject) {
  call_undfined_function();
  $resolve('success');
  $reject('An error accurred.');
}))->then(function() {

})->catch(function($res) {
  $res->getMessage();       // Output: Call to undefined function call_undfined_function()
  $res->getCode();          // Output: 0
  $res->getLine();          // Output: 8
  $res->getFile();          // Output: C:\xampp\htdocs\promise\index.php
  $res->getTraceAsString(); // Output: #1 C:\xampp\htdocs\promise\index.php(9): Modassir\Promise\Promise->__construct(Object(Closure))
})->finally(function() {
  // echo: strtoupper('Hello Worlds!');
});

OR

use Modassir\Promise\Promise;

$promise = new Promise(function($resolve, $reject) {
  $resolve('success');
  $reject('An error accurred.');
});

$promise->then(function($res) {
  // echo : 'success'
})->catch(function() {

})->finally(function() {
  // echo: strtoupper('Hello Worlds!');
});

$promise = new Promise(function($resolve, $reject) {
  call_undfined_function();
  $resolve('success');
  $reject('An error accurred.');
});

$promise->then(function() {

})->catch(function($res) {
  $res->getMessage();       // Output: Call to undefined function call_undfined_function()
  $res->getCode();          // Output: 0
  $res->getLine();          // Output: 8
  $res->getFile();          // Output: C:\xampp\htdocs\promise\index.php
  $res->getTraceAsString(); // Output: #1 C:\xampp\htdocs\promise\index.php(9): Modassir\Promise\Promise->__construct(Object(Closure))
})->finally(function() {
  // echo: strtoupper('Hello Worlds!');
});

Resources

About

The PHP Promise handling PHP promises with additional utilities and features.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages