Class: Farce::Transaction::RactorTVar

Inherits:
Object
  • Object
show all
Defined in:
lib/farce/integrations/ractor_sharing.rb

Overview

A Ractor::TVar staged alongside ordinary Farce participants.

Only the commit step enters Ractor.atomically. Conflicts retry the Farce attempt. Values are made shareable when assigned, matching TVar's setter. Mutating a contained object directly is a side effect of the attempt.

Run the Farce transaction outside an enclosing Ractor.atomically block. Writable Concurrent::TVar participants cannot join this commit step.

Examples:

Transfer between a TVar and an Atom

available = Ractor::TVar.new(10)
received  = Farce::Strict::Atom.new(0)
Farce.transaction do |tx|
  tx[available].value -= 3
  tx[received].value += 3
end

ractor-sharing Integration collapse

Methods included from Unshareable

#initialize, #ractor_shareable?

Dynamic Method Handling

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

Instance Method Details

#value ⇒ Object

Returns the value staged in this attempt.

Returns:

  • (Object) —

    the value staged in this attempt



91
# File 'lib/farce/integrations/ractor_sharing.rb', line 91

def value = access { @working.value }

#value=(value) ⇒ Object

Stage a shareable replacement.

Parameters:

  • value (Object) —

    the replacement value

Returns:

  • (Object) —

    the shareable replacement



96
97
98
99
100
101
102
# File 'lib/farce/integrations/ractor_sharing.rb', line 96

def value=(value)
  # Can't use #write, as a TVar's Ruby facade is always frozen
  access do
    @entry.write!
    @working.value = ::Ractor.make_shareable(value)
  end
end