[#81492] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — normalperson@...

Issue #13618 has been reported by normalperson (Eric Wong).

12 messages 2017/06/01

[ruby-core:81738] [Ruby trunk Feature#9145][Closed] Queue#pop(true) return nil if empty instead of raising ThreadError

From: glass.saga@...
Date: 2017-06-22 07:23:34 UTC
List: ruby-core #81738
Issue #9145 has been updated by Glass_saga (Masaki Matsushita).

Status changed from Feedback to Closed

Currently, Queue#pop takes non_block flag. 

----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-65440

* Author: jsc (Justin Collins)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.

Current behavior is to raise a ThreadError, with a message indicating the queue is empty.

For example:

q = Queue.new
begin
  loop do
    next_item = q.pop(true)
  end
rescue ThreadError
  # queue is empty...or maybe something bad happened
end

Instead, this could be

q = Queue.new
while next_item = q.pop(true)
end

Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread