class Concurrent::Exchanger
def exchange(value, timeout = nil)
-
(Object)
- the value exchanged by the other thread; nil if timed out
Parameters:
-
timeout
(Numeric
) -- the maximum time in second to wait for one other thread. nil (default value) means no timeout -
value
(Object
) -- the value to exchange with an other thread
def exchange(value, timeout = nil) first = @first.take(timeout) if first == MVar::TIMEOUT nil elsif first == EMPTY @first.put value second = @second.take timeout if second == MVar::TIMEOUT nil else second end else @first.put EMPTY @second.put value first end end
def initialize(opts = {})
def initialize(opts = {}) @first = MVar.new(EMPTY, opts) @second = MVar.new(MVar::EMPTY, opts) end