Class: Farce::Strict::Exchanger
- Inherits:
-
Abstract::Exchanger
- Object
- Abstract::Exchanger
- Farce::Strict::Exchanger
- Includes:
- Farce::Shareable::Unfreezable
- Defined in:
- lib/farce/strict/exchanger.rb
Overview
A Ractor-shareable rendezvous that exchanges shareable values directly. Values retain their identity and envelopes are returned unopened.
Instance Method Summary collapse
-
#exchange(offered, timeout: nil) { ... } ⇒ BasicObject?
Wait for a partner and return the partner's value.
-
#initialize ⇒ Exchanger
constructor
A new instance of Exchanger.
Methods included from Farce::Shareable
Methods included from Internal::Noncopyable
Constructor Details
#initialize ⇒ Exchanger
Returns a new instance of Exchanger.
12 13 14 15 |
# File 'lib/farce/strict/exchanger.rb', line 12 def initialize @exchanger = Internal::Exchanger.new super end |
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.
19 20 21 22 |
# File 'lib/farce/strict/exchanger.rb', line 19 def exchange(offered, timeout: nil, &) raise Ractor::IsolationError, "value must be Ractor-shareable" unless Ractor.shareable?(offered) super end |