class Concurrent::JavaExchanger
@!macro internal_implementation_note @!visibility private
Public Class Methods
new()
click to toggle source
# File lib/concurrent-ruby/concurrent/exchanger.rb, line 297 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-ruby/concurrent/exchanger.rb, line 306 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