1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-23 06:21:12 +01:00
parallel/examples/BlockingTask.php

33 lines
713 B
PHP
Raw Normal View History

2015-09-27 22:46:57 -05:00
<?php
2016-08-18 17:36:58 -05:00
namespace Amp\Concurrent\Example;
2015-09-27 22:46:57 -05:00
2016-08-18 17:36:58 -05:00
use Amp\Concurrent\Worker\{ Environment, 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
}
}