You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
require __DIR__ . '/vendor/autoload.php';
use function Amp\ParallelFunctions\parallelMap;
use function Amp\Promise\wait;
function myTestFunction($str){
//returns test
return substr($test, 0, -1);
}
$responses = wait(parallelMap([
'test1',
'test2',
'test3',
], function ($str) {
return myTestFunction($strt);
}));
var_dump($responses);
The text was updated successfully, but these errors were encountered:
<?php
require 'vendor/autoload.php';
use function Amp\ParallelFunctions\parallelMap;
use function Amp\Promise\wait;
$arguments = ['argument1', 'argument2', 'argument3'];
$responses = wait(parallelMap($arguments, function ($arg) {
// Call the custom function based on the argument
if ($arg === 'argument1') {
return customFunction1($arg);
} elseif ($arg === 'argument2') {
return customFunction2($arg);
} elseif ($arg === 'argument3') {
return customFunction3($arg);
}
}));
create a auto load file that have following code
<?php
function customFunction1($arg) {
// Simulate a time-consuming operation
sleep(4);
return "Result from customFunction1: $arg";
}
function customFunction2($arg) {
// Simulate a time-consuming operation
sleep(1);
return "Result from customFunction2: $arg";
}
function customFunction3($arg) {
// Simulate a time-consuming operation
sleep(3);
return "Result from customFunction3: $arg";
}
but it is waiting for customFunction1 output it is not parallel
How to call custom php function?
The text was updated successfully, but these errors were encountered: