How return data from the Swoole\Coroutine\Scheduler? #4462
Answered
by
twose
AkioSarkiz
asked this question in
Q&A
-
code $scheduler = $this->createScheduler();
$this->setUpScheduler($scheduler);
$scheduler->start(); How can I return data from |
Beta Was this translation helpful? Give feedback.
Answered by
twose
Nov 3, 2021
Replies: 2 comments 3 replies
-
you can use use Swoole\Coroutine;
Coroutine\run(function () {
$channel = new Coroutine\Channel(1);
go(function ($a, $b) use ($channel) {
Coroutine::sleep(1);
echo assert($a == 'hello') . PHP_EOL;
echo assert($b == 12345) . PHP_EOL;
$channel->push('done');
}, "hello", 12345);
var_dump($channel->pop());
}); |
Beta Was this translation helpful? Give feedback.
3 replies
-
I think I see what you mean, but you can only get data by reference vars or global vars for the time being... Coroutine\run(function () use (&$data) {
$channel = new Coroutine\Channel(1);
go(function ($a, $b) use ($channel) {
Coroutine::sleep(1);
echo assert($a == 'hello') . PHP_EOL;
echo assert($b == 12345) . PHP_EOL;
$channel->push('done');
}, "hello", 12345);
$data = $channel->pop();
});
var_dump($data); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AkioSarkiz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I see what you mean, but you can only get data by reference vars or global vars for the time being...