6 # is not good since not all of stdlib is safe with respect to
7 # asynchronous exceptions.
8 # This class is a safe implementation.
9 # See: http://www.ruby-forum.com/topic/107864
26 unless @readers.empty?
36 # @return nil if timeout
46 unless @messages.empty?
48 return @messages.shift
54 empty_cond = mon.new_cond
56 timeout_thread = Thread.new do
58 if empty_cond.wait(timeout)
61 @readers.delete reader
65 # timeout_thread was waked up before timeout
72 # either timeout or writer will send to us
75 # (try to) clean up timeout thread
77 mon.synchronize { empty_cond.signal }