Skip to content

Commit

Permalink
Add len for pool
Browse files Browse the repository at this point in the history
  • Loading branch information
shizacat committed Dec 5, 2022
1 parent 78fef8d commit 3af7062
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aio_pika/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ async def __aexit__(

await asyncio.ensure_future(self.close())

def __len__(self):
return len(self.__item_set)


class PoolItemContextManager(Generic[T], AsyncContextManager):
__slots__ = "pool", "item"
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async def create_instance():
return counter

pool = Pool(create_instance, max_size=max_size, loop=loop)
assert len(pool) == 0

async def getter():
nonlocal counter, pool
Expand All @@ -34,6 +35,8 @@ async def getter():

assert counter == max_size

assert len(pool) == max_size


class TestInstanceBase:
class Instance(PoolInstance):
Expand Down

0 comments on commit 3af7062

Please sign in to comment.