Skip to content

Commit c9022bb

Browse files
committed
RingbufQueue: add peek synchronous method.
1 parent 9c5489b commit c9022bb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

v3/docs/EVENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ Synchronous methods (immediate return):
507507
* `put_nowait` Arg: the object to put on the queue. Raises `IndexError` if the
508508
queue is full. If the calling code ignores the exception the oldest item in
509509
the queue will be overwritten. In some applications this can be of use.
510+
* `peek` No arg. Returns oldest entry without removing it from the queue. This
511+
is a superset of the CPython compatible methods.
510512

511513
Asynchronous methods:
512514
* `put` Arg: the object to put on the queue. If the queue is full, it will

v3/primitives/ringbuf_queue.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def get_nowait(self): # Remove and return an item from the queue.
3939
self._evget.clear()
4040
return r
4141

42+
def peek(self): # Return oldest item from the queue without removing it.
43+
# Return an item if one is immediately available, else raise QueueEmpty.
44+
if self.empty():
45+
raise IndexError
46+
return self._q[self._ri]
47+
4248
def put_nowait(self, v):
4349
self._q[self._wi] = v
4450
self._evput.set() # Schedule any tasks waiting on get

0 commit comments

Comments
 (0)