From: "hi@... (Joao Fernandes) via ruby-core" Date: 2023-09-29T11:16:06+00:00 Subject: [ruby-core:114921] [Ruby master Feature#19905] Introduce `Queue#peek` Issue #19905 has been updated by hi@joaofernandes.me (Joao Fernandes). ko1 (Koichi Sasada) wrote in #note-1: > Could you describe more about use cases? My main use case for this feature is observability and debugging. For example, I am experimenting with a car pooling simulation where multiple queues of passengers exist. I want to track the length of each queue, and how long the first passenger of each queue has been waiting. Thus, I would like to look at the first element of each queue without removing it, so that the workers can pick it up. I was also considering using this method to decide which queue to serve first. While I would still need to be careful with concurrency issues for this feature, `#peek` would be extremely helpful. Does this clarify potential use cases? Does it seem like a potential good addition to the language? ---------------------------------------- Feature #19905: Introduce `Queue#peek` https://bugs.ruby-lang.org/issues/19905#change-104789 * Author: hi@joaofernandes.me (Joao Fernandes) * Status: Open * Priority: Normal ---------------------------------------- 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]) => # 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. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/