1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
ClosedException我確實(shí)找到了解決這個(gè)問(wèn)題的方法,方法是在它被拋出后尋找并運(yùn)行其他任務(wù)。
\Amp\Loop::run(function () use ($fn, $st)
{
try
{
$connection = yield \Amp\Websocket\connect('wss://URL');
yield $connection->send('{"action":"auth","params":"KEYID"}');
yield $connection->send('{"action":"subscribe","params":"'.$st.'"}');
$i = 0;
while ($message = yield $connection->receive())
{
$i++;
$payload = yield $message->buffer();
$r = $fn($payload, $i);
if ($r == false) {
$connection->close();
break;
}
}
}
catch (\Amp\Websocket\ClosedException $e)
{
// do something here
}
}
);
- 1 回答
- 0 關(guān)注
- 127 瀏覽
添加回答
舉報(bào)