spatie / async

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

How to use external functions and variables? #202

Closed iyamk closed 1 year ago

iyamk commented 1 year ago

I make:

$pool[] = async(function () {
    global $vk;
    $vk->listen();
    return 2;
})->then(function (int $output) {
    echo 'ok';
});

And it throws an error because vk is NULL! it is in the global scope

And text output in a function is not displayed in the console

bhojkapderas commented 1 year ago

@iyamk

$global $vk;
$pool[] = async(function () use ($vk) {
    $vk->listen();
    return 2;
})->then(function (int $output) {
    echo 'ok';
});
spatie-bot commented 1 year ago

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.