PHP code example of thesebas / promise-async-await

1. Go to this page and download the library: Download thesebas/promise-async-await 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/ */

    

thesebas / promise-async-await example snippets


asyncRun(function ($init) {
    $res = yield asyncFunc($init);
    $res2 = yield all([asyncFunc($res + 1), asyncFunc($res + 1)]);
    $res3 = yield race([asyncFunc($res * 2), asyncFunc($res2 / 2)]);
    return "wow" . $init . $res . $res2 . $res3;
}, 0.1)->then(function ($result) {
    // ... $result is eq "wow".$init.$res.$res2.$res3;
});

$init = 0.1;
asyncFunc($init)->then(function ($res) {
    return all([asyncFunc($res + 1), asyncFunc($res + 1)]);
})->then(function ($res2) {
    return yield race([asyncFunc(/* $res? */), asyncFunc($res2 / 2)]);
})->then(function ($res3) {
    return "wow" ./* $init? */ /* $res?*/ /* $res2?*/ $res3
})->then(function ($result) {
    // ... $result is eq "wow".$res3;
});