class Queue
def close
def close @closed = true 2.times do Thread.pass num_waiting.times do push_without_close CLOSE_MESSAGE end end self end
def closed?
def closed? !!defined?(@closed) end
def pop_with_close(non_block = false)
def pop_with_close(non_block = false) begin r = pop_without_close(non_block || closed?) r unless CLOSE_MESSAGE == r rescue ThreadError raise if non_block || !closed? end end
def push_with_close(arg)
def push_with_close(arg) raise ClosedQueueError, 'queue closed' if closed? push_without_close(arg) end