Skip to content

Commit

Permalink
fix: py <3.10 doesn't have anext
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Aug 24, 2023
1 parent 84a2ea0 commit 6fd6e0a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions silverback/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ async def _get_response(self, request_id: int) -> dict:
if self._rpc_msg_buffer and self._rpc_msg_buffer[-1].get("id") == request_id:
return self._rpc_msg_buffer.pop()

await anext(self) # Keep pulling until we get a response
# NOTE: Python <3.10 does not support `anext` function
await self.__anext__() # Keep pulling until we get a response

raise RuntimeError("Timeout waiting for response.")

Expand Down Expand Up @@ -112,8 +113,9 @@ async def get_subscription_data(self, sub_id: str) -> AsyncGenerator[dict, None]
while True:
if not (queue := self._subscriptions.get(sub_id)) or queue.empty():
async with self._ws_lock:
# NOTE: Keep pulling until a message comes to process
await anext(self)
# Keep pulling until a message comes to process
# NOTE: Python <3.10 does not support `anext` function
await self.__anext__()
else:
yield await queue.get()

Expand Down

0 comments on commit 6fd6e0a

Please sign in to comment.