1. Steve Losh
  2. diesel

Commits

"Jam...@bumptechnologies.com>"  committed 4b1a37d

standard queue

  • Participants
  • Parent commits 8f7f4bc
  • Branches amqp

Comments (0)

Files changed (1)

File diesel/util/queue.py

View file
+from uuid import uuid4
+from collections import deque
+
+from diesel import wait, fire, up
+
+class QueueEmpty(Exception): pass
+
+class Queue(object):
+    def __init__(self):
+        self.wait_id = uuid4()
+        self.inp = deque()
+    
+    def put(self, i=None):
+        self.inp.append(i)
+        yield fire(self.wait_id)
+
+    def get(self, waiting=True):
+        if self.inp:
+            yield up(self.inp.popleft())
+        elif not waiting:
+            raise QueueEmpty()
+        else:
+            yield wait(self.wait_id)
+            yield up(self.inp.popleft())