class Concurrent::JavaExchanger

@!visibility private
@!macro internal_implementation_note

def do_exchange(value, timeout)

Returns:
  • (Object, CANCEL) - the value exchanged by the other thread; {CANCEL} on timeout
def do_exchange(value, timeout)
  result = nil
  if timeout.nil?
    Synchronization::JRuby.sleep_interruptibly do
      result = @exchanger.exchange(value)
    end
  else
    Synchronization::JRuby.sleep_interruptibly do
      result = @exchanger.exchange(value, 1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
    end
  end
  result
rescue java.util.concurrent.TimeoutException
  CANCEL
end

def initialize

def initialize
  @exchanger = java.util.concurrent.Exchanger.new
end