Skip to content

Commit

Permalink
feat: re-enable smart processing queue heap sorting
Browse files Browse the repository at this point in the history
but with less cpu usage than before
  • Loading branch information
BobTheBuidler authored Dec 16, 2024
1 parent 104bc0e commit 6f23180
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions a_sync/primitives/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,11 @@ def _get(self, heappop=heapq.heappop):
>>> task = queue._get()
>>> print(task)
"""
# NOTE: Since waiter priorities can change, this might not return the job with the
# most waiters if `self._queue` is not currently in order, but after calling `heappop`,
# `self._queue` will always be in proper order for next call to `self._get`.
return heappop(self._queue)
# NOTE: Since waiter priorities can change, heappop might not return the job with the
# most waiters if `self._queue` is not currently in order, but we can use `heappushpop`,
# to ensure we get the job with the most waiters.
queue = self._queue
return heappushpop(queue, heappop(queue))

def _get_key(self, *args, **kwargs) -> _SmartKey:
"""
Expand Down

0 comments on commit 6f23180

Please sign in to comment.