Class: Farce::Transaction::TVar
- Inherits:
-
Object
- Object
- Farce::Transaction::TVar
- Defined in:
- lib/farce/integrations/concurrent.rb
Overview
A Concurrent::TVar enrolled in a Farce transaction.
Read and assign through this wrapper to stage changes alongside Farce participants. Values retain their identity. Mutating a contained object directly is a side effect and cannot be rolled back.
Enrollment holds the TVar mutex until the attempt finishes. A busy mutex fails the attempt so it can be retried. Once enrolled, access the TVar through its wrapper to avoid trying to acquire its mutex again.
balance = Concurrent::TVar.new(10)
received = Farce::Atom.new(0)
Farce.transaction do |tx|
tx[balance].value -= 3
tx[received].value += 3
end
concurrent-ruby Integration collapse
-
#value ⇒ Object
Read the value staged in this attempt.
-
#value=(value) ⇒ Object
Stage a replacement value without modifying the original TVar.
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
Read the value staged in this attempt.
90 |
# File 'lib/farce/integrations/concurrent.rb', line 90 def value = access { @working.value } |
#value=(value) ⇒ Object
Stage a replacement value without modifying the original TVar.
95 96 97 |
# File 'lib/farce/integrations/concurrent.rb', line 95 def value=(value) write { @working.value = value } end |