Class: Farce::Transaction::RactorTMVar

Inherits:
Ractor::TMVar
  • Object
show all
Defined in:
lib/farce/integrations/ractor_tmvar.rb

Overview

A Ractor::TMVar staged alongside TVars and Farce participants.

Take, put, and swap operate on the value staged in this attempt. An empty read, take, or swap, or a put into a full TMVar fails the attempt. Farce.transaction retries these conditions within its retry limit. The try_* methods return nil or false without failing the attempt. Assigned values are made shareable, matching Ractor::TVar's setter.

Run outside Ractor.atomically, as required by RactorTVar. Calls from other Ractors require Ractor-safe TVar methods from ractor-sharing.

Examples:

Transfer from a TMVar to an Atom

pending  = Ractor::TMVar.new(10)
received = Farce::Strict::Atom.new(0)
Farce.transaction do |tx|
  tx[received].value += tx[pending].take
end

ractor-tmvar Integration collapse

Methods included from Unshareable

#ractor_shareable?

Constructor Details

#initialize(transaction, object) ⇒ RactorTMVar

Bind the TMVar's underlying TVar to this attempt's shared snapshot.

Parameters:

  • transaction (Transaction) —

    the current attempt

  • object (Ractor::TMVar) —

    the participant



34
35
36
37
38
39
# File 'lib/farce/integrations/ractor_tmvar.rb', line 34

def initialize(transaction, object)
  super
  # TMVar exposes no accessor for its storage. Reuse the TVar wrapper
  # so explicit enrollment of that same TVar shares all staged changes.
  compose(tvar: object.instance_variable_get(:@tvar))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Farce::Transaction::Wrapper