首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
Grpc 双向流读取会堵塞协程
``` Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]); Coroutine\run(function () { $client = new DataFusionGateway(); $metadata = [ 'session-id' => ['1'] , 'etcd-key' => ['1'] , 'sign' => ['1'] , ]; $st = $client->dataStream($metadata); Coroutine::create(function () use ($st) { while (true) { $posItem = new PositionItem(); $posItem->setSymbol('qqqq'); $posItem->setPosDate(1); $posItem->setPosType(1); $posItem->setBuyVol(1); $posItem->setSellVol(1); $posItem->setNetVol(1); $posItem->setContractMultiplier(1); $msg = DataFusionLink1::newPositionItem('aaa' , $posItem); var_dump($msg); $st->write($msg); Coroutine::create(function () use ($st) { while ($data = $st->read()) { var_dump((int)(microtime(true) * 1000)); if ($data === null) { $status = $st->getStatus(); echo "[STS] Failed to retry {$status->code}\n"; } echo "[DATA] received: " . json_encode($data->serializeToJsonString()) . "\n"; } }); var_dump('结束' . (int)(microtime(true) * 1000)); } }); }); ``` 我现在正在使用Grpc 的双向流模式进行读取和写入 这段代码运行后 协程中的$st->read()方法会堵塞整个协程,结果是等到read()有数据后才会打印出 ‘结束1752630770180’,请问这是为什么
发布于1年前 · 0 次浏览 · 来自
提问
AnYing
``` Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]); Coroutine\run(function () { $client = new DataFusionGateway(); $metadata = [ 'session-id' => ['1'] , 'etcd-key' => ['1'] , 'sign' => ['1'] , ]; $st = $client->dataStream($metadata); Coroutine::create(function () use ($st) { while (true) { $posItem = new PositionItem(); $posItem->setSymbol('qqqq'); $posItem->setPosDate(1); $posItem->setPosType(1); $posItem->setBuyVol(1); $posItem->setSellVol(1); $posItem->setNetVol(1); $posItem->setContractMultiplier(1); $msg = DataFusionLink1::newPositionItem('aaa' , $posItem); var_dump($msg); $st->write($msg); Coroutine::create(function () use ($st) { while ($data = $st->read()) { var_dump((int)(microtime(true) * 1000)); if ($data === null) { $status = $st->getStatus(); echo "[STS] Failed to retry {$status->code}\n"; } echo "[DATA] received: " . json_encode($data->serializeToJsonString()) . "\n"; } }); var_dump('结束' . (int)(microtime(true) * 1000)); } }); }); ``` 我现在正在使用Grpc 的双向流模式进行读取和写入 这段代码运行后 协程中的$st->read()方法会堵塞整个协程,结果是等到read()有数据后才会打印出 ‘结束1752630770180’,请问这是为什么
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
还没有评论!