2015-09-27 22:46:57 -05:00
|
|
|
<?php
|
|
|
|
namespace Icicle\Examples\Concurrent;
|
|
|
|
|
|
|
|
use Icicle\Concurrent\Worker\Environment;
|
2015-12-04 23:50:32 -06:00
|
|
|
use Icicle\Concurrent\Worker\Task;
|
2015-09-27 22:46:57 -05:00
|
|
|
|
2015-12-04 23:50:32 -06:00
|
|
|
class BlockingTask implements Task
|
2015-09-27 22:46:57 -05:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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 = array_slice(func_get_args(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function run(Environment $environment)
|
|
|
|
{
|
|
|
|
return call_user_func_array($this->function, $this->args);
|
|
|
|
}
|
|
|
|
}
|