1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-03 10:07:49 +01:00
parallel/examples/BlockingTask.php
Aaron Piotrowski da84a772cf Port to Amp
2016-08-18 11:04:48 -05:00

37 lines
744 B
PHP

<?php
namespace Amp\Examples\Concurrent;
use Amp\Concurrent\Worker\Environment;
use Amp\Concurrent\Worker\Task;
class BlockingTask implements Task
{
/**
* @var callable
*/
private $function;
/**
* @var mixed[]
*/
private $args;
/**
* @param callable $function Do not use a closure or non-serializable object.
* @param mixed ...$args Arguments to pass to the function. Must be serializable.
*/
public function __construct(callable $function, ...$args)
{
$this->function = $function;
$this->args = $args;
}
/**
* {@inheritdoc}
*/
public function run(Environment $environment)
{
return ($this->function)(...$this->args);
}
}