laravel-async icon indicating copy to clipboard operation
laravel-async copied to clipboard

AsyncFacade::run function issue

Open carlosMartin0213 opened this issue 2 years ago • 1 comments

I read your ReadMe and installed laravel-async to my current project. All things are worked well, but only one problem is occured. It is running synchronously.

use VXM\Async\AsyncFacade as Async;
for ($i = 1; $i < 20; $i++) {
    Async::run(function () use ($i) {
        sleep(1);
        return $i;
    });
}
var_dump(implode(', ', Async::wait()));

And run following command to add config file, and asyn.php like your code is added to config directory. php artisan vendor:publish --provider="VXM\Async\AsyncServiceProvider" --tag="config"

After running this code, I can get result like this. "string(65) "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19" Is there anything I need to configure my project to run asynchronously? Thanks.

carlosMartin0213 avatar Apr 24 '23 06:04 carlosMartin0213

@carlosMartin0213 as per the underlying library: https://github.com/spatie/async

You're probably missing the posix and pcntl extensions required in PHP to make it work. With that library, it falls back to synchronous by default.

kirkbushell avatar Aug 02 '23 02:08 kirkbushell