Class: Farce::Unshared::LeaseMap

Inherits:
Abstract::LeaseMap show all
Includes:
Farce::Unshareable
Defined in:
lib/farce/unshared/lease_map.rb

Overview

A thread-safe map that passes independently leased resources within one Ractor.

Examples:

Coordinating mutable resources between threads

leases = Farce::Unshared::LeaseMap.new { { jobs: [] } }
workers = 2.times.map do
  Thread.new { leases.checkout(:jobs) { |jobs| jobs << :finished } }
end
workers.each(&:join)
leases.checkout(:jobs, &:length) # => 2

Method Summary

Methods included from Farce::Unshareable

#initialize, #ractor_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, #initialize, #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?