Skip to content

Commit

Permalink
Merge pull request #1 from smithk86/master
Browse files Browse the repository at this point in the history
define __len__() to show number of active coroutines
  • Loading branch information
gistart authored Aug 21, 2019
2 parents b4902ac + b85173c commit 2c8cdd1
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 2c8cdd1

Please sign in to comment.