Class: Farce::Unshared::Atom

Inherits:
Abstract::Atom show all
Includes:
Farce::Unshareable
Defined in:
lib/farce/unshared/atom.rb

Overview

A thread-safe atomic reference that retains values directly within one Ractor. Mutable values keep their identity. Updates are serialized between threads.

Examples:

Updating an array atomically

atom = Farce::Unshared::Atom.new([])
atom.update { |items| items + [:job] }

Instance Method Summary collapse

Methods included from Farce::Unshareable

#ractor_shareable?

Methods inherited from Abstract::Atom

#blank?, #compare_and_set, #compare_by_identity?, #get, #store, #store_if_absent, #swap, #update, #upsert, #value, #value=, #wait_until, #wait_until_changed, #wait_until_match, #wait_until_non_nil, #wait_until_value, #wait_while, #wait_while_match, #wait_while_value

Methods included from Internal::ValueSerialization

#as_extended_json, #as_json, #to_bson, #to_bson_normalized_value, #to_cbor, #to_json, #to_msgpack

Methods included from Abstract::Value

#blank?, #unwrap, #value

Methods included from Internal::Copyable

#duplicable?

Constructor Details

#initialize(value = nil, compare_by_identity: false) ⇒ Atom

Returns a new instance of Atom.

Parameters:

  • value (BasicObject, nil) (defaults to: nil) —

    the initial value

  • compare_by_identity (Boolean) (defaults to: false) —

    whether comparisons use object identity



18
19
20
21
# File 'lib/farce/unshared/atom.rb', line 18

def initialize(value = nil, compare_by_identity: false)
  @atom = Internal::UnsharedAtom.new(value, compare_by_identity:)
  super()
end