Skip to content

Commit 521c38c

Browse files
committed
update: use a queue instead of an event
in theory the event is racy, even if it doesn't matter much here
1 parent d240813 commit 521c38c

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

app/fetch/update.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import functools
66
import sys
77
import traceback
8-
from asyncio import Event
98

109
from aiolimiter import AsyncLimiter
1110

@@ -26,19 +25,21 @@
2625

2726

2827
@functools.cache
29-
def _get_update_event() -> Event:
30-
return Event()
28+
def _get_update_queue() -> asyncio.Queue[None]:
29+
return asyncio.Queue(maxsize=1)
3130

3231

3332
async def wait_for_update() -> None:
34-
update_event = _get_update_event()
35-
await update_event.wait()
36-
update_event.clear()
33+
update_queue = _get_update_queue()
34+
await update_queue.get()
3735

3836

3937
def queue_update() -> None:
40-
update_event = _get_update_event()
41-
update_event.set()
38+
update_queue = _get_update_queue()
39+
try:
40+
update_queue.put_nowait(None)
41+
except asyncio.QueueFull:
42+
pass
4243

4344

4445
async def trigger_loop() -> None:

0 commit comments

Comments
 (0)