From: Suraj Kurapati <sunaku@gmail.com>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:38528] [Ruby 1.9 - Feature #4589] add Queue#each() method and include Enumerable
Date: Wed, 27 Jul 2011 03:21:37 +0900 [thread overview]
Message-ID: <redmine.journal-19737.20110727032107@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-4589.20110420214926@ruby-lang.org
Issue #4589 has been updated by Suraj Kurapati.
Perhaps this code example can better illustrate my request:
class Queue
def each(&block)
temporary_copy = @internal_queue_lock.synchronize do
@internal_item_array.dup
end
temporary_copy.each(&block)
end
end
Charles Nutter wrote:
> At first I thought this would be a good idea. But then I realized
> that #each is, in every case I can think of, a non-mutating
> operation.
Yes, that was my intention: read-only iteration of the queue.
> Since I assume you meant for Queue#each to pop all elements off
> the queue, this would be the first example I know of a mutating
> #each.
Sorry if my request was unclear, but that is not what I requested.
> Also, what happens when the queue is empty? Does it wait for
> another element, or does it end the iteration?
It should be non-blocking. Simply iterate over the items that are
currently in the queue.
If the method was blocking, it would never finish, because we would
never reach the "end" of the queue.
> The behavior of #each over a queue seems fuzzy to me, and without
> a clear specification of what you want I don't see a path forward.
I hope my responses above clarify this feature request.
Eric Hodel wrote:
> I don't think it is appropriate to include Enumerable. Too many
> methods from Enumerable seem inappropriate (or behavior would be
> application-specific). For example, should #find block, or only
> return items that match in the Queue?
Since Enumerable relies on #each(), and the Queue#each method I'm
requesting is non-blocking, all of the non-destructive Enumerable
methods (like #find, #select, #map) should work as we normally
expect them to.
> Should #reject remove items from the Queue, or only filter?
#reject should filter (read-only). #reject! should remove items.
> I can see differing needs depending on if the Queue has a single
> consumer or multiple consumers.
Hmm, shouldn't the thread-safe aspect of Queue take care of that?
----------------------------------------
Feature #4589: add Queue#each() method and include Enumerable
http://redmine.ruby-lang.org/issues/4589
Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:
=begin
Please add a thread-safe each() method to the Queue and SizedQueue classes
which are provided by the "thread" standard library
Also mix-in the Enumerable module into those classes so we can use map/inject/etc.
Thanks for your consideration.
=end
--
http://redmine.ruby-lang.org
next prev parent reply other threads:[~2011-07-26 18:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-20 12:49 [ruby-core:35828] [Ruby 1.9 - Feature #4589][Open] add Queue#each() method and include Enumerable redmine
2011-04-27 4:06 ` [ruby-core:35920] [Ruby 1.9 - Feature #4589] " Charles Nutter
2011-04-28 21:52 ` [ruby-core:35941] " Eric Hodel
2011-07-26 18:21 ` Suraj Kurapati [this message]
2011-07-26 23:34 ` [ruby-core:38536] " Eric Hodel
2011-07-27 9:41 ` [ruby-core:38559] " Alex Young
2012-03-25 6:20 ` [ruby-core:43618] [ruby-trunk - Feature #4589][Assigned] " mame (Yusuke Endoh)
2012-10-29 23:44 ` [ruby-core:48561] [ruby-trunk - Feature #4589][Feedback] " ko1 (Koichi Sasada)
2012-10-30 2:36 ` [ruby-core:48584] " Aaron Patterson
2017-01-31 9:10 ` [ruby-core:79348] [Ruby trunk Feature#4589][Closed] " ko1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-19737.20110727032107@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).