* [ruby-core:35828] [Ruby 1.9 - Feature #4589][Open] add Queue#each() method and include Enumerable
@ 2011-04-20 12:49 redmine
2011-04-27 4:06 ` [ruby-core:35920] [Ruby 1.9 - Feature #4589] " Charles Nutter
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: redmine @ 2011-04-20 12:49 UTC (permalink / raw
To: ruby-core
Issue #4589 has been reported by Suraj Kurapati.
----------------------------------------
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:
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.
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:35920] [Ruby 1.9 - Feature #4589] add Queue#each() method and include Enumerable
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 ` Charles Nutter
2011-04-28 21:52 ` [ruby-core:35941] " Eric Hodel
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Charles Nutter @ 2011-04-27 4:06 UTC (permalink / raw
To: ruby-core
Issue #4589 has been updated by Charles Nutter.
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. 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.
Also, what happens when the queue is empty? Does it wait for another element, or does it end the iteration?
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.
----------------------------------------
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:
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.
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:35941] [Ruby 1.9 - Feature #4589] add Queue#each() method and include Enumerable
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 ` Eric Hodel
2011-07-26 18:21 ` [ruby-core:38528] " Suraj Kurapati
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Eric Hodel @ 2011-04-28 21:52 UTC (permalink / raw
To: ruby-core
Issue #4589 has been updated by Eric Hodel.
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? Should #reject remove items from the Queue, or only filter?
I can see differing needs depending on if the Queue has a single consumer or multiple consumers.
----------------------------------------
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:
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.
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:38528] [Ruby 1.9 - Feature #4589] add Queue#each() method and include Enumerable
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
2011-07-26 23:34 ` [ruby-core:38536] " Eric Hodel
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Suraj Kurapati @ 2011-07-26 18:21 UTC (permalink / raw
To: ruby-core
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:38536] [Ruby 1.9 - Feature #4589] add Queue#each() method and include Enumerable
2011-04-20 12:49 [ruby-core:35828] [Ruby 1.9 - Feature #4589][Open] add Queue#each() method and include Enumerable redmine
` (2 preceding siblings ...)
2011-07-26 18:21 ` [ruby-core:38528] " Suraj Kurapati
@ 2011-07-26 23:34 ` 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)
` (2 subsequent siblings)
6 siblings, 1 reply; 10+ messages in thread
From: Eric Hodel @ 2011-07-26 23:34 UTC (permalink / raw
To: ruby-core
Issue #4589 has been updated by Eric Hodel.
There are no destructive methods in Enumerable.
Most times I use a Queue I am producing and consuming items at the same time so this would not be as useful for me since it works on a copy.
If I were to finish production of items or work with partial results this would be useful.
----------------------------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:38559] Re: [Ruby 1.9 - Feature #4589] add Queue#each() method and include Enumerable
2011-07-26 23:34 ` [ruby-core:38536] " Eric Hodel
@ 2011-07-27 9:41 ` Alex Young
0 siblings, 0 replies; 10+ messages in thread
From: Alex Young @ 2011-07-27 9:41 UTC (permalink / raw
To: ruby-core
On 27/07/11 00:34, Eric Hodel wrote:
>
> Issue #4589 has been updated by Eric Hodel.
>
>
> There are no destructive methods in Enumerable.
Enumerable gets mixed into IO, and #each on a Socket *is* destructive
(of the buffer contents). In that sense there is precedent for this sort
of behaviour.
--
Alex
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:43618] [ruby-trunk - Feature #4589][Assigned] add Queue#each() method and include Enumerable
2011-04-20 12:49 [ruby-core:35828] [Ruby 1.9 - Feature #4589][Open] add Queue#each() method and include Enumerable redmine
` (3 preceding siblings ...)
2011-07-26 23:34 ` [ruby-core:38536] " Eric Hodel
@ 2012-03-25 6:20 ` mame (Yusuke Endoh)
2012-10-29 23:44 ` [ruby-core:48561] [ruby-trunk - Feature #4589][Feedback] " ko1 (Koichi Sasada)
2017-01-31 9:10 ` [ruby-core:79348] [Ruby trunk Feature#4589][Closed] " ko1
6 siblings, 0 replies; 10+ messages in thread
From: mame (Yusuke Endoh) @ 2012-03-25 6:20 UTC (permalink / raw
To: ruby-core
Issue #4589 has been updated by mame (Yusuke Endoh).
Status changed from Open to Assigned
Assignee set to ko1 (Koichi Sasada)
----------------------------------------
Feature #4589: add Queue#each() method and include Enumerable
https://bugs.ruby-lang.org/issues/4589#change-25115
Author: sunaku (Suraj Kurapati)
Status: Assigned
Priority: Normal
Assignee: ko1 (Koichi Sasada)
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://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:48561] [ruby-trunk - Feature #4589][Feedback] add Queue#each() method and include Enumerable
2011-04-20 12:49 [ruby-core:35828] [Ruby 1.9 - Feature #4589][Open] add Queue#each() method and include Enumerable redmine
` (4 preceding siblings ...)
2012-03-25 6:20 ` [ruby-core:43618] [ruby-trunk - Feature #4589][Assigned] " mame (Yusuke Endoh)
@ 2012-10-29 23:44 ` 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
6 siblings, 1 reply; 10+ messages in thread
From: ko1 (Koichi Sasada) @ 2012-10-29 23:44 UTC (permalink / raw
To: ruby-core
Issue #4589 has been updated by ko1 (Koichi Sasada).
Status changed from Assigned to Feedback
Target version set to next minor
Professional's comments are very welcome.
I can't determine it should be worth or not.
----------------------------------------
Feature #4589: add Queue#each() method and include Enumerable
https://bugs.ruby-lang.org/issues/4589#change-31942
Author: sunaku (Suraj Kurapati)
Status: Feedback
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: lib
Target version: next minor
=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://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:48584] Re: [ruby-trunk - Feature #4589][Feedback] add Queue#each() method and include Enumerable
2012-10-29 23:44 ` [ruby-core:48561] [ruby-trunk - Feature #4589][Feedback] " ko1 (Koichi Sasada)
@ 2012-10-30 2:36 ` Aaron Patterson
0 siblings, 0 replies; 10+ messages in thread
From: Aaron Patterson @ 2012-10-30 2:36 UTC (permalink / raw
To: ruby-core
On Tue, Oct 30, 2012 at 08:44:21AM +0900, ko1 (Koichi Sasada) wrote:
>
> Issue #4589 has been updated by ko1 (Koichi Sasada).
>
> Status changed from Assigned to Feedback
> Target version set to next minor
>
> Professional's comments are very welcome.
> I can't determine it should be worth or not.
I don't think it's a good idea. There are different ways to make a
thread-safe `each`, and they have different behavior. For example:
class Queue
def each(&block)
@mutex.synchronize {
@que.each(&block)
}
end
end
compared to:
class Queue
def each(&block)
@que.dup.each(&block)
end
end
Both provide each, but the semantics are totally different. The first
one ensures that no other threads will update the queue, but that blocks
any threads from updating the queue. The second one doesn't block the
queue, but the values yielded to the block are inconsistent (e.g., a
thread could write to the queue after the internal array has been duped).
I think it's better to do this:
class Queue
def synchronize
@mutex.synchronize { yield }
end
def to_a; @que.dup; end
end
As a user, it's obvious you're getting a copy:
queue = Queue.new
queue.to_a.each { |item| ... }
If you want to block other threads from manipulating the queue while
iterating:
queue = Queue.new
queue.synchronize do
queue.to_a.each { |item| ... }
end
TL;DR: adding `sychronize` and `to_a` would be more powerful and less
invasive than adding `each` (IMO).
--
Aaron Patterson
http://tenderlovemaking.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
* [ruby-core:79348] [Ruby trunk Feature#4589][Closed] add Queue#each() method and include Enumerable
2011-04-20 12:49 [ruby-core:35828] [Ruby 1.9 - Feature #4589][Open] add Queue#each() method and include Enumerable redmine
` (5 preceding siblings ...)
2012-10-29 23:44 ` [ruby-core:48561] [ruby-trunk - Feature #4589][Feedback] " ko1 (Koichi Sasada)
@ 2017-01-31 9:10 ` ko1
6 siblings, 0 replies; 10+ messages in thread
From: ko1 @ 2017-01-31 9:10 UTC (permalink / raw
To: ruby-core
Issue #4589 has been updated by Koichi Sasada.
Status changed from Feedback to Closed
No discussion.
----------------------------------------
Feature #4589: add Queue#each() method and include Enumerable
https://bugs.ruby-lang.org/issues/4589#change-62771
* Author: Suraj Kurapati
* Status: Closed
* Priority: Normal
* Assignee: Koichi Sasada
* Target version: next minor
----------------------------------------
=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
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-01-31 8:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [ruby-core:38528] " Suraj Kurapati
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
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).