1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 22:11:11 +01:00
parallel/examples/BlockingTask.php

34 lines
729 B
PHP
Raw Normal View History

2015-09-27 22:46:57 -05:00
<?php
2016-08-23 16:47:40 -05:00
namespace Amp\Parallel\Example;
2015-09-27 22:46:57 -05:00
2017-05-18 09:51:31 +02:00
use Amp\Parallel\Worker\Environment;
use Amp\Parallel\Worker\Task;
2015-09-27 22:46:57 -05:00
2016-08-18 17:36:58 -05: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-08-18 17:36:58 -05: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-08-18 17:36:58 -05:00
public function run(Environment $environment) {
2016-01-24 23:04:29 -06:00
return ($this->function)(...$this->args);
2015-09-27 22:46:57 -05:00
}
}