2015-09-27 22:46:57 -05:00
|
|
|
<?php
|
2016-08-18 11:04:48 -05:00
|
|
|
namespace Amp\Examples\Concurrent;
|
2015-09-27 22:46:57 -05:00
|
|
|
|
2016-08-18 11:04:48 -05:00
|
|
|
use Amp\Concurrent\Worker\Environment;
|
|
|
|
use Amp\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.
|
|
|
|
*/
|
2016-01-23 00:00:56 -06:00
|
|
|
public function __construct(callable $function, ...$args)
|
2015-09-27 22:46:57 -05:00
|
|
|
{
|
|
|
|
$this->function = $function;
|
2016-01-23 00:00:56 -06:00
|
|
|
$this->args = $args;
|
2015-09-27 22:46:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2016-01-24 23:04:29 -06:00
|
|
|
public function run(Environment $environment)
|
2015-09-27 22:46:57 -05:00
|
|
|
{
|
2016-01-24 23:04:29 -06:00
|
|
|
return ($this->function)(...$this->args);
|
2015-09-27 22:46:57 -05:00
|
|
|
}
|
|
|
|
}
|