Skip to content

Commit

Permalink
Fix #86: Add property with that indicates if queue is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jul 28, 2018
1 parent e0fa84a commit 2129e6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changes

- Drop python 3.4 support and fix minimal version python3.5.3 #88

- Add property with that indicates if queue is closed #86

0.3.2 (2018-07-06)
------------------

Expand Down
12 changes: 12 additions & 0 deletions janus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ async def wait_closed(self):
return
await asyncio.wait(self._pending, loop=self._loop)

@property
def closed(self):
return self._closing and not self._pending

@property
def maxsize(self):
return self._maxsize
Expand Down Expand Up @@ -176,6 +180,10 @@ def __init__(self, parent):
def maxsize(self):
return self._parent._maxsize

@property
def closed(self):
return self._parent.closed

def task_done(self):
'''Indicate that a formerly enqueued task is complete.
Expand Down Expand Up @@ -340,6 +348,10 @@ class _AsyncQueueProxy:
def __init__(self, parent):
self._parent = parent

@property
def closed(self):
return self._parent.closed

def qsize(self):
"""Number of items in the queue."""
return self._parent._qsize()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,13 @@ def test_double_closing(self):
q.close()
q.close()
self.loop.run_until_complete(q.wait_closed())

def test_closed(self):
q = janus.Queue(loop=self.loop)
self.assertFalse(q.closed)
self.assertFalse(q.async_q.closed)
self.assertFalse(q.sync_q.closed)
q.close()
self.assertTrue(q.closed)
self.assertTrue(q.async_q.closed)
self.assertTrue(q.sync_q.closed)

0 comments on commit 2129e6f

Please sign in to comment.