Skip to content

Commit

Permalink
define __len__() to show number of active coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Smith committed Feb 5, 2019
1 parent b4902ac commit b85173c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion asyncio_pool/base_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async def __aenter__(self):
async def __aexit__(self, ext_type, exc, tb):
await self.join()

def __len__(self):
return len(self._waiting) + self.n_active

@property
def n_active(self):
'''Counts active coroutines'''
Expand All @@ -52,7 +55,7 @@ def is_empty(self):
@property
def is_full(self):
'''Returns `True` if `size` coroutines are already active.'''
return self.size <= len(self._waiting) + self.n_active
return self.size <= len(self)

async def join(self):
'''Waits (blocks) for all spawned coroutines to finish, both active and
Expand Down

0 comments on commit b85173c

Please sign in to comment.