25 lines
558 B
Python
25 lines
558 B
Python
from collections import deque
|
|
from itertools import takewhile
|
|
|
|
from funcy import repeatedly
|
|
|
|
from pyinfra.server.dispatcher.dispatcher import is_not_nothing, Nothing
|
|
|
|
|
|
def stream_queue(queue):
|
|
yield from takewhile(is_not_nothing, repeatedly(queue.popleft))
|
|
|
|
|
|
class Queue:
|
|
def __init__(self):
|
|
self.__queue = deque()
|
|
|
|
def append(self, package) -> None:
|
|
self.__queue.append(package)
|
|
|
|
def popleft(self):
|
|
return self.__queue.popleft() if self.__queue else Nothing
|
|
|
|
def __bool__(self):
|
|
return bool(self.__queue)
|