Class: Farce::Strict::WeakAtom

Inherits:
Abstract::WeakAtom show all
Includes:
Farce::Shareable::Delegated
Defined in:
lib/farce/strict/weak_atom.rb

Overview

A Ractor-shareable weak atomic reference that stores shareable values directly.

Examples:

Referencing a shareable object without keeping it alive

resource = Object.new.freeze
atom     = Farce::Strict::WeakAtom.new(resource, compare_by_identity: true)
atom.value.equal?(resource) # => true

resource = nil
# Once the object is collected, atom.value returns nil.

Lazily storing a shareable value

atom  = Farce::Strict::WeakAtom.new
value = atom.store_if_absent { [1, 2, 3].freeze }
atom.value.equal?(value) # => true
# Keeping value referenced also keeps the atom's referent alive.

Method Summary

Methods included from Farce::Shareable

#initialize, #ractor_shareable?

Methods inherited from Abstract::WeakAtom

#initialize

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?