Class: Farce::WeakMap

Inherits:
Abstract::WeakMap show all
Includes:
Shareable::Delegated, Internal::WeakMapValueModes
Defined in:
lib/farce/weak_map.rb

Overview

A Ractor-shareable concurrent map with weak shareable keys and weak values. Entries disappear after a weakly held object is collected.

Supported modes are :raise (the default), :make_shareable, and :dedup. Modes apply only to values. Keys must already be shareable.

With :dedup, retain the canonical result returned by store or update, as it might differ from the input and could be immediately collected. Assignment evaluates to the input rather than the canonical result.

Examples:

Publishing a value without retaining it strongly

key      = Object.new.freeze
value    = []
map      = Farce::WeakMap.new(mode: :make_shareable)
map[key] = value
map[key].equal?(value) # => true

Method Summary

Methods included from Shareable

#initialize, #ractor_shareable?

Methods inherited from Abstract::WeakMap

#weak_keys?, #weak_values?

Methods inherited from Abstract::ConcurrentMap

#[], #[]=, #clear, #compact!, #compact_blank!, #compare_and_set, #compare_keys_by_identity?, #compare_values_by_identity?, #delete, #delete_if, #each, #each_key, #each_value, #fetch, #get, #getkey, #keep_if, #key?, #keys, #merge!, #reject!, #reverse_merge!, #select!, #size, #store, #store_if_absent, #swap, #transform_values!, #update, #upsert, #values, #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 Abstract::DuplicableMap

#compact, #compact_blank, #deep_dup, #duplicable?, #except, #flatten, #invert, #merge, #reject, #reverse_merge, #select, #slice, #stringify_keys, #symbolize_keys, #to_proc, #transform_keys, #transform_values, #with_indifferent_access

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?