tleckie / async
Asynchronous and parallel PHP
Fund package maintenance!
teodoroleckie
www.paypal.com/donate?business=ZHYA2MTGA4884¤cy_code=USD
Requires
- php: ^8
- opis/closure: ^3.6
- symfony/process: ^5.2
Requires (Dev)
- friendsofphp/php-cs-fixer: v3.0.0-beta.2
- phpunit/phpunit: ^9.5
Suggests
- ext-pcntl: Required to use async processes
- ext-posix: Required to use async processes
README
Installation
You can install the package via composer:
composer require tleckie/async
Usage
<?php 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();
Catch exception
<?php 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();