Skip to content

Commit

Permalink
Rename events -> event_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Nov 9, 2023
1 parent 39a6316 commit 9e47ffa
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/fontra_rcjk/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
class ConcurrentCallLimiter:
def __init__(self):
self.num_calls_in_progress = 0
self.events = []
self.event_queue = []

@asynccontextmanager
async def limit(self):
if self.num_calls_in_progress >= MAX_CONCURRENT_CALLS:
if not self.events:
if not self.event_queue:
logger.info("limiting concurrent API calls")
event = asyncio.Event()
self.events.append(event)
self.event_queue.append(event)
await event.wait()

self.num_calls_in_progress += 1
try:
yield
finally:
self.num_calls_in_progress -= 1
if self.num_calls_in_progress < MAX_CONCURRENT_CALLS and self.events:
event = self.events.pop(0)
if self.num_calls_in_progress < MAX_CONCURRENT_CALLS and self.event_queue:
event = self.event_queue.pop(0)
event.set()
if not self.events:
if not self.event_queue:
logger.info("done limiting concurrent API calls")


Expand Down

0 comments on commit 9e47ffa

Please sign in to comment.