Class: Farce::Abstract::Exchanger

Inherits:
Object
  • Object
show all
Includes:
Internal::Noncopyable, Internal::Inspect
Defined in:
lib/farce/abstract/exchanger.rb

Overview

A rendezvous where callers pair up and receive each other's offered value. Each call participates in one exchange. The exchanger can be reused by any number of callers.

Direct Known Subclasses

Exchanger, Strict::Exchanger

Instance Method Summary collapse

Methods included from Internal::Noncopyable

#duplicable?

Instance Method Details

#exchange(offered, timeout: nil) { ... } ⇒ BasicObject?

Wait for a partner and return the partner's value. Offering nil allows a caller to receive a value without sending a payload. A timeout of zero only exchanges with a partner that is already waiting. A successful exchange of nil does not invoke the fallback.

Parameters:

  • offered (BasicObject, nil) —

    the value to give to the partner

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

    the maximum seconds to wait, or nil to wait indefinitely

Yields:

  • called without arguments when the timeout expires

Returns:

  • (BasicObject, nil) —

    the partner's value, or the fallback result or nil on timeout

Raises:

  • (ArgumentError) —

    if the timeout is negative or not finite



23
# File 'lib/farce/abstract/exchanger.rb', line 23

def exchange(offered, timeout: nil, &) = @exchanger.exchange(offered, timeout:, &)