PHP code example of fyre / promise

1. Go to this page and download the library: Download fyre/promise library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fyre / promise example snippets


use Fyre\Promise\Promise;

$promise = new Promise($callback);

$callback = function(Closure $resolve, Closure $reject): void {
    $resolve();
};

$promise->catch($onRejected);

$promise->finally($onFinally);

$promise->then($onFulfilled, $onRejected);

use \Fyre\Promise\AsyncPromise;

$promise = new AsyncPromise(function(Closure $resolve, Closure $reject): void {
    // this will be executed on a forked process
    sleep(3);

    $resolve(1);
})->then(function(int $value): void {
    // this will be executed on the main thread

    echo $value;
});

$promise->wait();

$promise->cancel($message);

$promise->wait();

$promise = Promise::any($promises);

$promise = Promise::all($promises);

try {
    $resolvedValue = Promise::await($promise);
} catch (Throwable $reason) {
    //...
}

$promise = Promise::all($promises);

$promise = Promise::reject($reason);

$promise = Promise::resolve($value);