class Object
Constants
- ClosableQueue
A wrapper around
Queue
to provide support for `#close`.Once closed, threads waiting on dequeue will drain the queue and then receive nil on future dequeues. If close(true) is used, pop from an empty closed queue or attempts to push raise
ClosedQueue
, a subclass ofStopIteration
.Example usage: queue = ClosableQueue.new consumer = Thread.new { while number = queue.pop ; puts number ; end } 5.times {|x| queue.push(x) } queue.close consumer.join
`#close` is thread-safe and can be called safely multiple times.
This is anticipated to be obsolete by Ruby 2.3 with Queue#close.