From: naruse@... Date: 2020-12-10T08:36:54+00:00 Subject: [ruby-core:101370] [Ruby master Feature#17357] `Queue#pop` should have a block form for clsoed queues Issue #17357 has been updated by naruse (Yui NARUSE). Status changed from Open to Feedback Do you have a use case? The issue is well discussed in [Feature #10600] and concluded as current spec. To discuss again we need new materials. ---------------------------------------- Feature #17357: `Queue#pop` should have a block form for clsoed queues https://bugs.ruby-lang.org/issues/17357#change-89079 * Author: marcandre (Marc-Andre Lafortune) * Status: Feedback * Priority: Normal ---------------------------------------- It is currently difficult to reliably distinguish a `nil` value in a queue from the `nil` that is returned when a Queue is closed: ```ruby n = 100_000 result = [] t2 = Thread.new { n.times { Thread.pass }} # to make things less predictable n.times.count do q = Queue.new t = Thread.new { q.pop; result << q.closed? } q << nil q.close t.join end puts result.count(true) # => some number usually > 9990 and < 10000 ```` To be completely sure, one needs a Mutex or wrap/unwrap `nil` values. `Queue#pop` should offer a surefire way to handle closed queues. I propose that an optional block be called in this case: ```ruby q = Queue.new.close q.pop # => nil q.pop { :closed } # => :closed ```` Proposed PR: https://github.com/ruby/ruby/pull/3830 -- https://bugs.ruby-lang.org/ Unsubscribe: