Module: Farce::Local

Defined in:
lib/farce/local.rb,
lib/farce/local/map.rb,
lib/farce/local/set.rb,
lib/farce/local/atom.rb,
lib/farce/local/flag.rb,
lib/farce/local/lazy.rb,
lib/farce/local/lease.rb,
lib/farce/local/queue.rb,
lib/farce/local/scoped.rb,
lib/farce/local/vector.rb,
lib/farce/local/counter.rb,
lib/farce/local/lfu_map.rb,
lib/farce/local/lru_map.rb,
lib/farce/local/lazy_ref.rb,
lib/farce/local/molecule.rb,
lib/farce/local/tree_map.rb,
lib/farce/local/weak_map.rb,
lib/farce/local/weak_set.rb,
lib/farce/local/lease_map.rb,
lib/farce/local/weak_atom.rb,
lib/farce/local/lease_pool.rb,
lib/farce/local/sorted_set.rb,
lib/farce/local/timer_queue.rb,
lib/farce/local/weak_key_map.rb,
lib/farce/local/priority_queue.rb,
lib/farce/local/weak_value_map.rb,
lib/farce/integrations/active_support/map.rb

Overview

Shareable containers whose mutable contents belong to the current scope. Scopes may be :ractor, :thread_group, :thread, :fiber_storage, or :fiber. Initial contents are copied between Ractors. Within a Ractor, each scope has its own container, but objects supplied as initial contents may be shared.

Defined Under Namespace

Modules: Scoped Classes: Atom, Counter, Flag, LFUMap, LRUMap, Lazy, LazyRef, Lease, LeaseMap, LeasePool, Map, Molecule, PriorityQueue, Queue, Set, SortedSet, TimerQueue, TreeMap, Vector, WeakAtom, WeakKeyMap, WeakMap, WeakSet, WeakValueMap

Class Method Summary collapse

Class Method Details

.enfarce(object, freeze: nil, scope: :ractor) {|object| ... } ⇒ BasicObject

Converts vanilla Ruby objects into their Farce::Local equivalents.

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.

Examples:

Farce::Local.enfarce({ foo: ["bar"] })
# =>  #<Farce::Local::Map {foo: #<Farce::Local::Vector ["bar"]>}>

Parameters:

  • object (BasicObject) —

    The root object to convert

  • freeze (Boolean, nil) (defaults to: nil) —

    Whether to freeze the converted objects. If set to nil (default), the freezing behavior will depend on the original object's frozen state.

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

    The scope for the local container, e.g., :ractor.

Yields:

  • (object) —

    Optional block, called with any object that doesn't have a specific conversion defined.

Yield Parameters:

  • object (BasicObject) —

    the object to convert

Yield Returns:

  • (BasicObject) —

    the converted object

Returns:

  • (BasicObject) —

    the converted object

See Also:



33
# File 'lib/farce/local.rb', line 33

def self.enfarce(object, **, &) = Internal::Converter.new(self, **, &).convert(object)