Skip to content

Commit 07271b2

Browse files
committed
Use existing send sync method
1 parent 4f976f6 commit 07271b2

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
from app.logger import on_flush
32
import os
43

@@ -9,7 +8,7 @@ def __init__(self, server):
98
self.cols = None
109
self.rows = None
1110
self.subscriptions = set()
12-
on_flush(self.send_messages_sync)
11+
on_flush(self.send_messages)
1312

1413
def update_size(self):
1514
sz = os.get_terminal_size()
@@ -33,31 +32,16 @@ def subscribe(self, client_id):
3332
def unsubscribe(self, client_id):
3433
self.subscriptions.discard(client_id)
3534

36-
def send_messages_sync(self, entries):
35+
def send_messages(self, entries):
3736
if not len(entries) or not len(self.subscriptions):
3837
return
3938

40-
try:
41-
loop = asyncio.get_running_loop()
42-
except RuntimeError:
43-
loop = None
44-
45-
if loop and loop.is_running():
46-
loop.create_task(self.send_messages(entries))
47-
else:
48-
asyncio.run(self.send_messages(entries))
49-
50-
async def send_messages(self, entries):
51-
if not len(entries):
52-
return
53-
5439
new_size = self.update_size()
55-
40+
5641
for client_id in self.subscriptions:
5742
if client_id not in self.server.sockets:
5843
# Automatically unsub if the socket has disconnected
5944
self.unsubscribe(client_id)
6045
continue
6146

62-
await self.server.send_json(
63-
"logs", {"entries": entries, "size": new_size}, client_id)
47+
self.server.send_sync("logs", {"entries": entries, "size": new_size}, client_id)

0 commit comments

Comments
 (0)