wilkques/task-pool

dev-master 2023-08-16 05:22 UTC

This package is auto-updated.

Last update: 2024-11-16 08:02:33 UTC


README

TESTS Latest Stable Version License

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

  1. memory memory size default 1024
  2. timeout set timeout microseconds default 100000