ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each
@ 2013-07-15 15:44 avdi (Avdi Grimm)
  2013-07-15 15:54 ` [ruby-core:56020] [ruby-trunk - Feature #8639] " rkh (Konstantin Haase)
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: avdi (Avdi Grimm) @ 2013-07-15 15:44 UTC (permalink / raw
  To: ruby-core


Issue #8639 has been reported by avdi (Avdi Grimm).

----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639

Author: avdi (Avdi Grimm)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56020] [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
@ 2013-07-15 15:54 ` rkh (Konstantin Haase)
  2013-07-15 16:00   ` [ruby-core:56022] " Avdi Grimm
  2013-07-15 20:24 ` [ruby-core:56029] Re: [ruby-trunk - Feature #8639][Open] " Alex Young
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: rkh (Konstantin Haase) @ 2013-07-15 15:54 UTC (permalink / raw
  To: ruby-core


Issue #8639 has been updated by rkh (Konstantin Haase).


+1 for the feature, should have gone into CommonRuby, I think.
----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-40510

Author: avdi (Avdi Grimm)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56022] Re: [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:54 ` [ruby-core:56020] [ruby-trunk - Feature #8639] " rkh (Konstantin Haase)
@ 2013-07-15 16:00   ` Avdi Grimm
  2013-07-15 16:02     ` [ruby-core:56023] " Avdi Grimm
  0 siblings, 1 reply; 15+ messages in thread
From: Avdi Grimm @ 2013-07-15 16:00 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

On Mon, Jul 15, 2013 at 11:54 AM, rkh (Konstantin Haase) <me@rkh.im> wrote:

> +1 for the feature, should have gone into CommonRuby, I think.


Is that something I can change?

[-- Attachment #2: Type: text/html, Size: 467 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56023] Re: [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 16:00   ` [ruby-core:56022] " Avdi Grimm
@ 2013-07-15 16:02     ` Avdi Grimm
  0 siblings, 0 replies; 15+ messages in thread
From: Avdi Grimm @ 2013-07-15 16:02 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 118 bytes --]

P.S. Should I reply on the ticket or do these conversations eventually get
posted back to it? I'm new to all of this!

[-- Attachment #2: Type: text/html, Size: 143 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56029] Re: [ruby-trunk - Feature #8639][Open] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
  2013-07-15 15:54 ` [ruby-core:56020] [ruby-trunk - Feature #8639] " rkh (Konstantin Haase)
@ 2013-07-15 20:24 ` Alex Young
  2013-07-15 20:52   ` [ruby-core:56030] " Avdi Grimm
  2013-08-07  0:53 ` [ruby-core:56421] [ruby-trunk - Feature #8639] " ko1 (Koichi Sasada)
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Alex Young @ 2013-07-15 20:24 UTC (permalink / raw
  To: ruby-core

On Tue, 2013-07-16 at 00:44 +0900, avdi (Avdi Grimm) wrote:
> Issue #8639 has been reported by avdi (Avdi Grimm).

I thought this sounded familiar.  It has come up before:
http://bugs.ruby-lang.org/issues/4589

-- 
Alex


> 
> ----------------------------------------
> Feature #8639: Add Queue#each
> https://bugs.ruby-lang.org/issues/8639
> 
> Author: avdi (Avdi Grimm)
> Status: Open
> Priority: Normal
> Assignee: 
> Category: 
> Target version: 
> 
> 
> I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361
> 
> As for why, it makes for a convenient way to build consumer processes:
> 
>   inq = Queue.new
>   outq = Queue.new
>   doubler = Thread.new do
>     inq.each do |n|
>       outq << n + n
>     end
>   end
> 
> My PR also returns an Enumerator when no block is given, and handles the non_block argument.
> 
> I'm sure there's some good reason that this method wasn't there already, so feel free to explain.
> 
> Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.
> 
> Thanks!
> 
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56030] Re: [ruby-trunk - Feature #8639][Open] Add Queue#each
  2013-07-15 20:24 ` [ruby-core:56029] Re: [ruby-trunk - Feature #8639][Open] " Alex Young
@ 2013-07-15 20:52   ` Avdi Grimm
  2013-07-15 21:04     ` [ruby-core:56031] " Avdi Grimm
  0 siblings, 1 reply; 15+ messages in thread
From: Avdi Grimm @ 2013-07-15 20:52 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]

On Mon, Jul 15, 2013 at 4:24 PM, Alex Young <alex@blackkettle.org> wrote:

> I thought this sounded familiar.  It has come up before:
> http://bugs.ruby-lang.org/issues/4589
>

Hey, thanks for finding that! I figured it had probably come up before.
Some notes responding to that conversation:

- First, as Alex pointed out then, IO#each is often destructive in the
sense that it's either moving the read pointer forward or (in the case of a
pipe or socket) losing info once it advances. So there IS a precedent.
- I feel like the semantics I've implemented in the PR are moderately sane,
but feel free to point out anything I've missed.
- "Loop forever over the things coming out of this queue until something
breaks the loop" seems like a common enough use case to warrant some sugar.
- Note this is NOT "loop until the queue is exhausted", unless you turn
non_block on.
- I am explicitly not discussing the inclusion of Enumerable in this
ticket. That's a much bigger can of worms and I haven't even begun to think
through all the implications.
- Note, though, that with this PR if you DO want a full Enumerable over a
queue all you have to do now is say `q.each`, omitting the block. So we're
not making Queue enumerable, but we're making it easy to get at a queue
Enumerator if you really want one. Without this PR the shortest code I've
found to do that is:

  q = Queue.new
  eq = Enumerator.new do |y|
    loop do
      y << q.shift
    end
  end

...and this code doesn't cover all the cases that I've covered in the PR.

[-- Attachment #2: Type: text/html, Size: 2583 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56031] Re: [ruby-trunk - Feature #8639][Open] Add Queue#each
  2013-07-15 20:52   ` [ruby-core:56030] " Avdi Grimm
@ 2013-07-15 21:04     ` Avdi Grimm
  0 siblings, 0 replies; 15+ messages in thread
From: Avdi Grimm @ 2013-07-15 21:04 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

BTW, I feel like I've left out the biggest justification for this, which
for me is POLS. What prompted me to submit the PR was that I actually
started writing an example of using Queue#each---it just made sense for it
to exist, so much so I thought I remembered using it before---and then
realized it wasn't there. To me it felt very natural and intuitive to
expect Queue#each to exist. YMMV, obviously, but #each is such a widespread
convention in Ruby that it seems natural to look for it on a Queue class.

OK, I'll shut up now :-)

[-- Attachment #2: Type: text/html, Size: 601 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56421] [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
  2013-07-15 15:54 ` [ruby-core:56020] [ruby-trunk - Feature #8639] " rkh (Konstantin Haase)
  2013-07-15 20:24 ` [ruby-core:56029] Re: [ruby-trunk - Feature #8639][Open] " Alex Young
@ 2013-08-07  0:53 ` ko1 (Koichi Sasada)
  2013-08-09 10:42 ` [ruby-core:56483] " ko1 (Koichi Sasada)
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: ko1 (Koichi Sasada) @ 2013-08-07  0:53 UTC (permalink / raw
  To: ruby-core


Issue #8639 has been updated by ko1 (Koichi Sasada).


# Please assume
#  @q_buf is current buffer (array) of queue in following example.
#  @q_lock is lock of this Queue.

People think Queue#each should be:

(1) Infinite loop

  # iterate forever
  def each
    loop{
      yield @q_buf.shift
    }
  end

(2) Finite loop

(2-1) Mutable behavior

  # iterate untile elements are exists
  def each
    loop{
      e = nil
      @q_lock.lock{
        return if @q_buf.empty?
        @q_buf.shift
      }
      yield e
    }
  end

(2-2) Immutable behaviour

  def each(&b)
    @q_buf.dup.each(&b)
  end
  # only for chekcking current elements
  # not for inter-thraed communication

# Please add another possible version.


Your proposal is (1). (1) is shorter version of

  while e = q.pop
    break if e == :end
    ...
  end

which I wrote frequently.

  q.each{|e|
    break if e == :end
    ...
  }



I'm weak negative because
  (a) seems not so convinient
  (b) #each method is for Enumerable
      If we find #each method, then we think it is Enumerable.
  (c) we have only few cases for infinite iteration #each methods.
  (d) I can think 3 versions described above with in seconds.


BTW, I think your `non-blocking' parameter should be a switch of (1) and (2-1).



----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-40951

Author: avdi (Avdi Grimm)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!


-- 
http://bugs.ruby-lang.org/
_______________________________________________
ruby-core mailing list
ruby-core@ruby-lang.org
http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-core

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56483] [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
                   ` (2 preceding siblings ...)
  2013-08-07  0:53 ` [ruby-core:56421] [ruby-trunk - Feature #8639] " ko1 (Koichi Sasada)
@ 2013-08-09 10:42 ` ko1 (Koichi Sasada)
  2013-08-14 21:00 ` [ruby-core:56622] " zzak (Zachary Scott)
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: ko1 (Koichi Sasada) @ 2013-08-09 10:42 UTC (permalink / raw
  To: ruby-core


Issue #8639 has been updated by ko1 (Koichi Sasada).

Assignee set to ko1 (Koichi Sasada)


----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-41031

Author: avdi (Avdi Grimm)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: 
Target version: 


I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56622] [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
                   ` (3 preceding siblings ...)
  2013-08-09 10:42 ` [ruby-core:56483] " ko1 (Koichi Sasada)
@ 2013-08-14 21:00 ` zzak (Zachary Scott)
  2013-08-14 21:56   ` [ruby-core:56623] " Avdi Grimm
  2013-09-30 11:24 ` [ruby-core:57483] [ruby-trunk - Feature #8639][Feedback] " ko1 (Koichi Sasada)
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: zzak (Zachary Scott) @ 2013-08-14 21:00 UTC (permalink / raw
  To: ruby-core


Issue #8639 has been updated by zzak (Zachary Scott).

File 361.patch added

Attaching the patch from Avdi's pull request on github, thank you!
----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-41160

Author: avdi (Avdi Grimm)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: 
Target version: 


I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:56623] Re: [ruby-trunk - Feature #8639] Add Queue#each
  2013-08-14 21:00 ` [ruby-core:56622] " zzak (Zachary Scott)
@ 2013-08-14 21:56   ` Avdi Grimm
  0 siblings, 0 replies; 15+ messages in thread
From: Avdi Grimm @ 2013-08-14 21:56 UTC (permalink / raw
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 1431 bytes --]

Thanks! I'm off to a conf this week, it probably would have been a awhile
before I got around to it.


On Wed, Aug 14, 2013 at 5:00 PM, zzak (Zachary Scott) <e@zzak.io> wrote:

>
> Issue #8639 has been updated by zzak (Zachary Scott).
>
> File 361.patch added
>
> Attaching the patch from Avdi's pull request on github, thank you!
> ----------------------------------------
> Feature #8639: Add Queue#each
> https://bugs.ruby-lang.org/issues/8639#change-41160
>
> Author: avdi (Avdi Grimm)
> Status: Open
> Priority: Normal
> Assignee: ko1 (Koichi Sasada)
> Category:
> Target version:
>
>
> I was fiddling around with Queue the other day and realized it doesn't
> have an #each method. So I made one: https://github.com/ruby/ruby/pull/361
>
> As for why, it makes for a convenient way to build consumer processes:
>
>   inq = Queue.new
>   outq = Queue.new
>   doubler = Thread.new do
>     inq.each do |n|
>       outq << n + n
>     end
>   end
>
> My PR also returns an Enumerator when no block is given, and handles the
> non_block argument.
>
> I'm sure there's some good reason that this method wasn't there already,
> so feel free to explain.
>
> Also, this is my first Ruby feature ticket so please let me know if I'm
> missing any points of protocol.
>
> Thanks!
>
>
> --
> http://bugs.ruby-lang.org/
>



-- 
Avdi Grimm
http://avdi.org

I only check email twice a day. to reach me sooner, go to
http://awayfind.com/avdi

[-- Attachment #2: Type: text/html, Size: 2328 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:57483] [ruby-trunk - Feature #8639][Feedback] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
                   ` (4 preceding siblings ...)
  2013-08-14 21:00 ` [ruby-core:56622] " zzak (Zachary Scott)
@ 2013-09-30 11:24 ` ko1 (Koichi Sasada)
  2014-11-07 16:19 ` [ruby-core:66134] [ruby-trunk - Feature #8639] " nobu
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: ko1 (Koichi Sasada) @ 2013-09-30 11:24 UTC (permalink / raw
  To: ruby-core


Issue #8639 has been updated by ko1 (Koichi Sasada).

Category set to lib
Status changed from Open to Feedback
Target version set to next minor

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/56421
any comments?
----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-42096

Author: avdi (Avdi Grimm)
Status: Feedback
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: lib
Target version: next minor


I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:66134] [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
                   ` (5 preceding siblings ...)
  2013-09-30 11:24 ` [ruby-core:57483] [ruby-trunk - Feature #8639][Feedback] " ko1 (Koichi Sasada)
@ 2014-11-07 16:19 ` nobu
  2014-11-07 16:20 ` [ruby-core:66136] " nobu
  2017-01-31  9:44 ` [ruby-core:79361] [Ruby trunk Feature#8639][Closed] " ko1
  8 siblings, 0 replies; 15+ messages in thread
From: nobu @ 2014-11-07 16:19 UTC (permalink / raw
  To: ruby-core

Issue #8639 has been updated by Nobuyoshi Nakada.

Description updated

----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-49840

* Author: Avdi Grimm
* Status: Feedback
* Priority: Normal
* Assignee: Koichi Sasada
* Category: lib
* Target version: next minor
----------------------------------------
I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  ~~~ruby
  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end
  ~~~

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!

---Files--------------------------------
361.patch (3.34 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:66136] [ruby-trunk - Feature #8639] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
                   ` (6 preceding siblings ...)
  2014-11-07 16:19 ` [ruby-core:66134] [ruby-trunk - Feature #8639] " nobu
@ 2014-11-07 16:20 ` nobu
  2017-01-31  9:44 ` [ruby-core:79361] [Ruby trunk Feature#8639][Closed] " ko1
  8 siblings, 0 replies; 15+ messages in thread
From: nobu @ 2014-11-07 16:20 UTC (permalink / raw
  To: ruby-core

Issue #8639 has been updated by Nobuyoshi Nakada.

Related to Bug #10485: NoMethodError "undefined method `initialize_copy'" when trying to execute Queue#dup added

----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-49842

* Author: Avdi Grimm
* Status: Feedback
* Priority: Normal
* Assignee: Koichi Sasada
* Category: lib
* Target version: next minor
----------------------------------------
I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  ~~~ruby
  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end
  ~~~

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!

---Files--------------------------------
361.patch (3.34 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:79361] [Ruby trunk Feature#8639][Closed] Add Queue#each
  2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
                   ` (7 preceding siblings ...)
  2014-11-07 16:20 ` [ruby-core:66136] " nobu
@ 2017-01-31  9:44 ` ko1
  8 siblings, 0 replies; 15+ messages in thread
From: ko1 @ 2017-01-31  9:44 UTC (permalink / raw
  To: ruby-core

Issue #8639 has been updated by Koichi Sasada.

Status changed from Feedback to Closed

No discussion.

----------------------------------------
Feature #8639: Add Queue#each
https://bugs.ruby-lang.org/issues/8639#change-62787

* Author: Avdi Grimm
* Status: Closed
* Priority: Normal
* Assignee: Koichi Sasada
* Target version: next minor
----------------------------------------
I was fiddling around with Queue the other day and realized it doesn't have an #each method. So I made one: https://github.com/ruby/ruby/pull/361

As for why, it makes for a convenient way to build consumer processes:

  ~~~ruby
  inq = Queue.new
  outq = Queue.new
  doubler = Thread.new do
    inq.each do |n|
      outq << n + n
    end
  end
  ~~~

My PR also returns an Enumerator when no block is given, and handles the non_block argument.

I'm sure there's some good reason that this method wasn't there already, so feel free to explain.

Also, this is my first Ruby feature ticket so please let me know if I'm missing any points of protocol.

Thanks!

---Files--------------------------------
361.patch (3.34 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-01-31  9:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-15 15:44 [ruby-core:56019] [ruby-trunk - Feature #8639][Open] Add Queue#each avdi (Avdi Grimm)
2013-07-15 15:54 ` [ruby-core:56020] [ruby-trunk - Feature #8639] " rkh (Konstantin Haase)
2013-07-15 16:00   ` [ruby-core:56022] " Avdi Grimm
2013-07-15 16:02     ` [ruby-core:56023] " Avdi Grimm
2013-07-15 20:24 ` [ruby-core:56029] Re: [ruby-trunk - Feature #8639][Open] " Alex Young
2013-07-15 20:52   ` [ruby-core:56030] " Avdi Grimm
2013-07-15 21:04     ` [ruby-core:56031] " Avdi Grimm
2013-08-07  0:53 ` [ruby-core:56421] [ruby-trunk - Feature #8639] " ko1 (Koichi Sasada)
2013-08-09 10:42 ` [ruby-core:56483] " ko1 (Koichi Sasada)
2013-08-14 21:00 ` [ruby-core:56622] " zzak (Zachary Scott)
2013-08-14 21:56   ` [ruby-core:56623] " Avdi Grimm
2013-09-30 11:24 ` [ruby-core:57483] [ruby-trunk - Feature #8639][Feedback] " ko1 (Koichi Sasada)
2014-11-07 16:19 ` [ruby-core:66134] [ruby-trunk - Feature #8639] " nobu
2014-11-07 16:20 ` [ruby-core:66136] " nobu
2017-01-31  9:44 ` [ruby-core:79361] [Ruby trunk Feature#8639][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).