I'm using the Amp\Loop and want to know that what is the correct way of calling class method with arguments in $worker->enqueue(new CallableTask()).
Here is an example:
<?php
require_once "vendor/autoload.php";
use Amp\Loop;
use Amp\Parallel\Worker\CallableTask;
use Amp\Parallel\Worker\DefaultWorkerFactory;
class Test_Amp {
public function __construct() {
$this->run_test();
}
public function run_test() {
Amp\Loop::run(function () {
$a = "";
$b = "";
$factory = new DefaultWorkerFactory();
$worker = $factory->create();
$result = yield $worker->enqueue(new CallableTask(array(&$this, 'run_task'), [$a, $b])); // Is it the correct way of calling run_task() ?
$code = yield $worker->shutdown();
});
}
public function run_task($a, $b) {
//do something with $a and $b
}
}
new Test_Amp();