Skip to content

Commit

Permalink
优化publish
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Apr 9, 2024
1 parent f714bcd commit f4caedc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,23 @@ public function publish(array $data)
*/
public function publishToClients(string $appKey, string $channel, string $event, $data, ?string $socketId = null)
{
$timerId = Timer::add(0.1, function () use (
&$timerId, $appKey, $channel, $event, $data, $socketId
) {
try {
$res = ChannelClient::publish(self::PRIVATE_CHANNEL_PUBLISH_TO_CLIENT, [
$appKey, $channel, $event, $data, $socketId
]);
if ($res !== false) {
Timer::del($timerId);
if ($res === false) {
$timerId = Timer::add(0.1, function () use (
&$timerId, $appKey, $channel, $event, $data, $socketId
) {
$res = ChannelClient::publish(self::PRIVATE_CHANNEL_PUBLISH_TO_CLIENT, [
$appKey, $channel, $event, $data, $socketId
]);
if ($res !== false) {
Timer::del($timerId);
}
});
}
});

} catch (\Throwable $throwable) {}
}

/**
Expand Down

0 comments on commit f4caedc

Please sign in to comment.