Class: Farce::Local::LeaseMap
- Inherits:
-
Abstract::LeaseMap
- Object
- Abstract::Map
- Abstract::LeaseMap
- Farce::Local::LeaseMap
- Includes:
- Scoped, Shareable::Unfreezable
- Defined in:
- lib/farce/local/lease_map.rb
Overview
A shareable lease map with independently initialized resources in each scope.
Instance Attribute Summary
Attributes included from Scoped
Instance Method Summary collapse
-
#initialize(scope: :ractor, normalize_keys: nil) { ... } ⇒ LeaseMap
constructor
Create a map that initializes once on first use in each scope.
Methods included from Shareable
Methods inherited from Abstract::LeaseMap
#[], #[]=, #auto_lease, #available?, #checked_out?, #checkin, #checkout, #clear, #compare_keys_by_identity?, #compare_values_by_identity?, #delete, #duplicable?, #each, #each_key, #each_value, #fetch, #getkey, #key?, #keys, #lease_for, #owned?, #shareable_keys?, #shareable_values?, #size, #store_if_absent, #to_a, #to_h, #try_checkout, #values
Methods inherited from Abstract::Map
#[], #[]=, #as_extended_json, #as_json, #assert_valid_keys, #assoc, #bson_type, #clear, #compare_by_identity?, #compare_keys_by_identity?, #compare_values_by_identity?, #deconstruct_keys, #delete, #dig, #each, #each_key, #each_pair, #each_value, #empty?, #fetch, #fetch_values, #getkey, #has_key?, #key, #key?, #keys, #length, #rassoc, #shareable_keys?, #shareable_values?, #size, #store, #store_if_absent, #to_a, #to_bson, #to_bson_normalized_value, #to_cbor, #to_h, #to_hash, #to_json, #to_msgpack, #to_query, #to_s, #value?, #values_at, #weak_keys?, #weak_values?
Constructor Details
#initialize(scope: :ractor, normalize_keys: nil) { ... } ⇒ LeaseMap
Create a map that initializes once on first use in each scope. 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.
23 24 25 26 27 28 |
# File 'lib/farce/local/lease_map.rb', line 23 def initialize(scope: :ractor, normalize_keys: nil, &initializer) raise ArgumentError, "a resource constructor block is required" unless initializer @initializer = Ractor.shareable?(initializer) ? initializer : Ractor.shareable_proc(&initializer) super(scope:, normalize_keys:) end |