Class: Farce::Transaction::Mutable

Inherits:
Mutable
  • Object
show all
Defined in:
lib/farce/transaction/mutable.rb

Overview

A Mutable that stages method calls within a transaction.

Reads use the attempt's current snapshot. Mutations replace only its staged value and are published with the other participants when the attempt commits. Snapshots must be frozen. Use a dedicated transaction participant for a shareable object whose state can change while it remains unfrozen.

Method Summary

Methods included from Unshareable

#ractor_shareable?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ BasicObject (private)

rubocop:disable Style/MissingRespondToMissing



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/farce/transaction/mutable.rb', line 40

def method_missing(name, ...) # rubocop:disable Style/MissingRespondToMissing
  access do
    ::Kernel.raise(::NoMethodError, "transaction wrappers cannot be frozen") if name == :freeze
    begin
      @atom.value.__send__(name, ...)
    rescue ::FrozenError
      result = nil
      @atom.update do |current|
        copy = current.dup
        result = copy.__send__(name, ...)
        result = self if result.equal?(copy)
        copy.freeze
      end
      result
    end
  end
end