Project

General

Profile

Actions

Feature #19905

open

Introduce `Queue#peek`

Added by hi@joaofernandes.me (Joao Fernandes) 7 months ago. Updated 3 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:114915]

Description

This ticket proposes the introduction of the Queue#peek method, similar to what we can find in other object oriented languages such as Java and C#. This method is similar to Queue#pop, but does not change the data, nor does it require a lock.

q = Queue.new([1,2,3])
=> #<Thread::Queue:0x00000001065d7148>
q.peek
=> 1
q.peek
=> 1

I have felt the need of this for debugging, but I think that it can also be of practical use for presentation. I believe that the only drawback could be that newcomers could misuse it in multi-threaded work without taking into account that this method is not thread safe.

I also volunteer myself to implement this method.

Actions

Also available in: Atom PDF

Like2
Like0Like1Like0Like0Like0Like1Like0