Class: Farce::Local::Atom

Inherits:
Abstract::Atom show all
Includes:
Shareable::Tracked
Defined in:
lib/farce/local/atom.rb

Overview

A shareable atomic reference with an independent mutable value in each scope.

Instance Attribute Summary

Attributes included from Scoped

#scope

Instance Method Summary collapse

Methods included from Shareable

#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, scope: :ractor) ⇒ Atom

Valid scopes are:

  • :ractor - The value is shared by all threads within the same Ractor.
  • :thread_group - The value is shared by all threads within the same thread group.
  • :thread - The value is shared by all fibers within the same thread.
  • :fiber_storage - The value is shared by all fibers using the same storage. Unless explicitly specified, storage is inherited from the parent fiber for blocking fibers, but not for non-blocking fibers (such as those created by Scheduler#schedule).
  • :fiber - Each fiber has its own independent value.

Parameters:

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

    the initial value

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

    whether comparisons use object identity instead of equality

  • scope (Symbol) (defaults to: :ractor) —

    the scope of the atomic reference



15
16
17
18
19
20
21
# File 'lib/farce/local/atom.rb', line 15

class Atom < Abstract::Atom
  include Shareable::Tracked
  include Scoped::Tracked

  protected def internal_atom = scoped_value
  private def new_scoped_value(...) = Internal::UnsharedAtom.new(...)
end