Skip to content

Commit

Permalink
expose the unfinished tasks variable (#34)
Browse files Browse the repository at this point in the history
* expose the unfinished tasks variable

* changed to property for consistency with Queue and added test cases

* remove whitespace
  • Loading branch information
richardbaronpenman authored and asvetlov committed Feb 22, 2017
1 parent faaee9c commit 316eb58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions janus/__init__.py
Expand Up @@ -219,6 +219,11 @@ def qsize(self):
'''Return the approximate size of the queue (not reliable!).'''
return self._parent._qsize()

@property
def unfinished_tasks(self):
'''Return the number of unfinished tasks.'''
return self._parent._unfinished_tasks

def empty(self):
'''Return True if the queue is empty, False otherwise (not reliable!).
Expand Down Expand Up @@ -341,6 +346,11 @@ def qsize(self):
"""Number of items in the queue."""
return self._parent._qsize()

@property
def unfinished_tasks(self):
'''Return the number of unfinished tasks.'''
return self._parent._unfinished_tasks

@property
def maxsize(self):
"""Number of items allowed in the queue."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_mixed.py
Expand Up @@ -43,6 +43,20 @@ def test_maxsize_default(self):
q = janus.Queue(loop=self.loop)
self.assertIs(0, q.maxsize)

def test_unfinished(self):
q = janus.Queue(loop=self.loop)
self.assertEqual(q.sync_q.unfinished_tasks, 0)
self.assertEqual(q.async_q.unfinished_tasks, 0)
q.sync_q.put(1)
self.assertEqual(q.sync_q.unfinished_tasks, 1)
self.assertEqual(q.async_q.unfinished_tasks, 1)
q.sync_q.get()
self.assertEqual(q.sync_q.unfinished_tasks, 1)
self.assertEqual(q.async_q.unfinished_tasks, 1)
q.sync_q.task_done()
self.assertEqual(q.sync_q.unfinished_tasks, 0)
self.assertEqual(q.async_q.unfinished_tasks, 0)

def test_sync_put_async_get(self):
q = janus.Queue(loop=self.loop)

Expand Down

0 comments on commit 316eb58

Please sign in to comment.