It always returns exceptions
illiamorkva opened this issue · comments
Hi everyone, I'm trying to execute this code:
`$pool = Pool::create();
echo Pool::isSupported(); // true
echo "Supported" . extension_loaded('pcntl'); // true
echo "Supported" . extension_loaded('posix'); // true
foreach (range(1, 5) as $i) {
$pool->add(function () use ($i) {
// Do a thing
$output = $i * 2;
return $output;
})->then(function (int $output) {
echo $output . "\n";
// Handle success
})->catch(function (Throwable $exception) {
// Handle exception
echo 'error';
});
}
$pool->wait();`
My environment:
Docker, PHP 7.4
All extensions are loaded and Pool::isSupported(); returns true
but I always see errors in the catch block...
when I debug this exception, I see an exception with an empty message
local.ERROR: Spatie\Async\Output\ParallelError in /var/www/vendor/spatie/async/src/Output/ParallelError.php:11
Could you help me, thanks
Same error here. Any updates on this? Running in a docker container
Try to use this syntax with async and await functions:
`$pool = Pool::create();
foreach (range(1, 5) as $i) {
$pool[] = async(function () use ($i) {
// Something to execute in a child process.
})->then(function (int $output) {
// Handle output returned from the child process.
})->catch(function (Exception $exception) {
// Handle exceptions thrown in the child process.
});
}
await($pool);`
it works well
It seems that any output to stderr is flagged as an error and then through serialisation, passed back and turned into a thrown exception.
I'm just looking at whether I can stop warnings being thrown as exceptions (in my case exif warnings that are perfectly fine to have with external images) as it stops me from being able to see the results.
(This could be unrelated to this particular problem of course)
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.