From: Joel VanderWerf Date: 2013-11-24T18:55:01-08:00 Subject: [ruby-core:58562] Re: [ruby-trunk - Feature #9145][Feedback] Queue#pop(true) return nil if empty instead of raising ThreadError On 11/23/2013 08:30 PM, Glass_saga (Masaki Matsushita) wrote: > 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 Or what about a new method, Queue#pop?, which is always non-blocking and non-raising. It would behave like: class Queue def pop? pop(true) rescue ThreadError nil end end q = Queue.new q << 1 q << 2 q << 3 while x=q.pop? p x end __END__ output: 1 2 3