spatie / async

Easily run code asynchronously
https://spatie.be/en/opensource/php
MIT License
2.65k stars 179 forks source link

Sleep issue #205

Closed santossoares closed 1 year ago

santossoares commented 1 year ago

Hello! Idk if this is expected or not, but when using sleep on the main php process, the script wakes up after the child process it's execution.

See this example:

$pool = Pool::create(); $pool->add(function () { sleep(2); return 'end'; })->then(function ($output){ echo $output; });

echo "first sleep".PHP_EOL; sleep(20);

echo "second sleep".PHP_EOL; sleep(5);

$pool->wait();

After 2 seconds, the sleep(20) gets interrupted. Then, the code continues to execute as expected.

PavelPronskiy commented 1 year ago

You need install php-pcntl and php-posix.

santossoares commented 1 year ago

Thx. I'll try this and see if the output changes.