PHP code example of tleckie / async

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

    

tleckie / async example snippets




use Tleckie\Async\Async;

$async = new Async();

foreach([1,2,3,4,5,6,7,8,9,10] as $value){

    $async->add(static function() use($value){
    
        sleep(1);
        
        return $value*2;
        
    })->then(static function($value){
        
        var_dump($value);
        
    })->catch(static function(\Exception $exception){
    
        var_dump($exception->getMessage());
    });
}

$async->wait();



use Tleckie\Async\Async;

$async = new Async();

$async->add(static function (){

    throw new \Exception('Error...');

})->then(static function ($value) {

})->catch(static function ($exception) {

    var_dump($exception);
});

$async->wait();