Skip to content

Commit

Permalink
Merge pull request #333 from nats-io/sub-async-iter
Browse files Browse the repository at this point in the history
Fix async iterator not decreasing pending data size
  • Loading branch information
wallyqs committed Aug 15, 2022
2 parents 4269801 + 9f1c680 commit 06825e0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nats/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Subscription,
)

__version__ = '2.1.5'
__version__ = '2.1.6'
__lang__ = 'python3'
_logger = logging.getLogger(__name__)
PROTOCOL = 1
Expand Down
1 change: 1 addition & 0 deletions nats/aio/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ async def __anext__(self) -> Msg:
if get_task in finished:
self._queue.task_done()
msg = get_task.result()
self._sub._pending_size -= len(msg.data)

# Unblock the iterator in case it has already received enough messages.
if sub._max_msgs > 0 and sub._received >= sub._max_msgs:
Expand Down
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ async def iterator_func(sub):
self.assertEqual(5, len(msgs))
self.assertEqual("tests.1", msgs[1].subject)
self.assertEqual("tests.3", msgs[3].subject)
self.assertEqual(0, sub.pending_bytes)
await nc.close()

@async_test
Expand Down

0 comments on commit 06825e0

Please sign in to comment.