Skip to content

hsharrison/history-queue

Repository files navigation

Overview

tests
Travis-CI Build Status
Coverage Status
package PyPI Package latest release PyPI Package monthly downloads PyPI Wheel Supported versions Supported implementations

asyncio.Queue with history:

Objects put on a HistoryQueue are gathered in tuples, with the first element being the next item on the queue, followed by items add previously.

HistoryQueue can also be thought of as as asynchronous collections.deque, with put analogous to deque.appendleft and get returning the entire deque (as a tuple).

>>> from hqueue import HistoryQueue
>>> hq = HistoryQueue(history_size=2)
>>> hq.put_nowait(0)
>>> hq.put_nowait(1)
>>> hq.get_nowait()
(0,)
>>> hq.get_nowait()
(1, 0)
>>> hq.put_nowait(2)
>>> hq.put_nowait(3)
>>> hq.put_nowait(4)
>>> hq.get_nowait()
(2, 1, 0)
>>> hq.get_nowait()
(3, 2, 1)

For ease of illustration, in the above examples we use put_nowait and get_nowait, the synchronous counterparts of put and wait, respectively. In a coroutine, await put() could be used to block until the queue is not full, and await get() to block until there is an item in the queue.

See Also

asyncio.Queue collections.deque

About

asyncio.Queue with history

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages