From: "Glass_saga (Masaki Matsushita)" Date: 2013-11-24T13:30:08+09:00 Subject: [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] Queue#pop(true) return nil if empty instead of raising ThreadError Issue #9145 has been updated by Glass_saga (Masaki Matsushita). Category changed from lib to ext Status changed from Open to Feedback I think we can't change default behavior of Queue#pop(true) because some code expects ThreadError to be raised. However, it may be possible to introduce new keyword argument like following: q = Queue.new while next_item = q.pop(true, exception: false) # it doesn't raise ThreadError and returns nil. # do something end ---------------------------------------- Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError https://bugs.ruby-lang.org/issues/9145#change-43126 Author: jsc (Justin Collins) Status: Feedback Priority: Normal Assignee: Category: ext 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. -- http://bugs.ruby-lang.org/