# thread-blocking receive for Spread
# by Ned Konz
#
require 'spread.so'

class Spread

  alias_method(:blocking_receive, :receive)

  def receive_wait(timeout = nil)
     @mbox_io = IO.new(mbox(), 'r') unless @mbox_io
    return IO.select([ @mbox_io ], nil, nil, timeout)
  end

  def receive(timeout = nil)
    receive_wait(timeout)
    blocking_receive()
  end

end
