wilkques / task-pool
task-pool
dev-master
2023-08-16 05:22 UTC
Requires
- wilkques/php-helper: ^3.0.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-16 07:50:02 UTC
README
Installation
composer require wilkques/task-pool
How to use
use Wilkques\TaskPool\Contracts\TaskContract; use Wilkques\TaskPool\Exceptions\ForkRunTimeException; class TaskOne implements TaskContract { public function handle() { // ... do something return $result; } public function resolved($result, $index) { // ... do something return $result; } public function rejected(ForkRunTimeException $forkRunTimeException) { // ... do something return $forkRunTimeException; } } class TaskTwo implements TaskContract { public function handle() { // ... do something return $result; } public function resolved($result, $index) { // ... do something return $result; } public function rejected(ForkRunTimeException $forkRunTimeException) { // ... do something return $forkRunTimeException; } } class TaskThree implements TaskContract { public function handle() { // ... do something return $result; } public function resolved($result, $index) { // ... do something return $result; } public function rejected(ForkRunTimeException $forkRunTimeException) { // ... do something return $forkRunTimeException; } } $taskOne = new TaskOne; $taskTwo = new TaskTwo; $taskThree = new TaskThree; $taskPool = new TaskPool; $taskPool->task($taskOne)->task($taskTwo)->task($taskThree); // or $taskPool->tasks( array( $taskOne, $taskTwo, $taskThree, ) ); // run handle $taskPool->handle(); // if has return $taskPool->results();
Options
memory
memory size default 1024timeout
set timeout microseconds default 100000