amphp / parallel

An advanced parallelization library for PHP, enabling efficient multitasking, optimizing resource use, and application responsiveness through multiple CPU threads.
MIT License
779 stars 64 forks source link

not get response from call a user function #122

Closed aabhishek04 closed 1 year ago

aabhishek04 commented 4 years ago

I'am not getting response from user define methods . is there any way to get response to hit user method and get response...

<?php

use Amp\Parallel\Worker; use Amp\Promise;

class TestController {

public function getSum($a,$b){
    return $a+$b;
}
public function getDivsion($a,$b){
    return $a/$b;
}
public function getMultipel($a,$b){
    return $a*$b;
}

public function algoExecution()
{ 

    $funs = [
        $this->getSum(2,2),
        $this->getDivsion(2,2),
        $this->getMultipel(2,2)
    ];

    $promises = [];
    foreach ($funs as $fun) {
            $promises[] = Worker\enqueueCallable('call_user_func',$fun);
    }

    $responses = Promise\wait(Promise\all($promises));

    foreach ($responses as $key => $response) {
        \printf($response, $key);
    }

}

}