Method: Concurrent#exchange

Defined in:
lib/concurrent-ruby/concurrent/exchanger.rb

#exchange(value, timeout = nil) ⇒ Object

Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return. The timeout value indicates the approximate number of seconds the method should block while waiting for the exchange. When the timeout value is ‘nil` the method will block indefinitely.

In some edge cases when a ‘timeout` is given a return value of `nil` may be ambiguous. Specifically, if `nil` is a valid value in the exchange it will be impossible to tell whether `nil` is the actual return value or if it signifies timeout. When `nil` is a valid value in the exchange consider using #exchange! or #try_exchange instead.

Parameters:

  • value (Object)

    the value to exchange with another thread

  • timeout (Numeric, nil) (defaults to: nil)

    in seconds, ‘nil` blocks indefinitely

Returns:

  • (Object)

    the value exchanged by the other thread or ‘nil` on timeout



# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 341