1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00
parallel/examples/BlockingTask.php

39 lines
797 B
PHP
Raw Normal View History

2015-09-28 05:46:57 +02:00
<?php
2017-11-10 18:35:47 +01:00
2016-08-23 23:47:40 +02:00
namespace Amp\Parallel\Example;
2015-09-28 05:46:57 +02:00
2017-05-18 09:51:31 +02:00
use Amp\Parallel\Worker\Environment;
use Amp\Parallel\Worker\Task;
2015-09-28 05:46:57 +02:00
2016-08-19 00:36:58 +02:00
class BlockingTask implements Task {
2015-09-28 05:46:57 +02: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-19 00:36:58 +02:00
public function __construct(callable $function, ...$args) {
2015-09-28 05:46:57 +02:00
$this->function = $function;
2016-01-23 07:00:56 +01:00
$this->args = $args;
2015-09-28 05:46:57 +02:00
}
/**
* {@inheritdoc}
*/
2016-08-19 00:36:58 +02:00
public function run(Environment $environment) {
2016-01-25 06:04:29 +01:00
return ($this->function)(...$this->args);
2015-09-28 05:46:57 +02:00
}
2017-11-20 19:21:53 +01:00
public function getArgs() {
return $this->args;
}
2015-09-28 05:46:57 +02:00
}