Skip to content

Commit

Permalink
Don't recreate string for every ping (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegt0rr authored Feb 12, 2024
1 parent 0b62999 commit 2cd91ea
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aiohttp_sse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ async def _ping(self) -> None:
# periodically send ping to the browser. Any message that
# starts with ":" colon ignored by a browser and could be used
# as ping message.
message = ": ping{0}{0}".format(self._sep).encode("utf-8")
while True:
await asyncio.sleep(self._ping_interval)
try:
await self.write(": ping{0}{0}".format(self._sep).encode("utf-8"))
await self.write(message)
except (ConnectionResetError, RuntimeError):
# RuntimeError - on writing after EOF
break
Expand Down

0 comments on commit 2cd91ea

Please sign in to comment.