class Concurrent::JavaExchanger

@!macro exchanger @!macro internal_implementation_note @!visibility private

Public Class Methods

new() click to toggle source

@!macro exchanger_method_initialize

# File lib/concurrent/exchanger.rb, line 307
def initialize
  @exchanger = java.util.concurrent.Exchanger.new
end

Private Instance Methods

do_exchange(value, timeout) click to toggle source

@!macro exchanger_method_do_exchange

@return [Object, CANCEL] the value exchanged by the other thread; {CANCEL} on timeout

# File lib/concurrent/exchanger.rb, line 316
def do_exchange(value, timeout)
  if timeout.nil?
    @exchanger.exchange(value)
  else
    @exchanger.exchange(value, 1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
  end
rescue java.util.concurrent.TimeoutException
  CANCEL
end