Class: Farce::Unshared::LeasePool

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

Overview

A thread-safe pool that passes resource references within one Ractor.

Examples:

Reusing objects from multiple threads

pool = Farce::Unshared::LeasePool.new(max_size: 1) { { uses: 0 } }
workers = 2.times.map do
  Thread.new { pool.checkout { |state| state[:uses] += 1 } }
end
workers.each(&:join)

pool.checkout { |state| state[:uses] } # => 2

Instance Attribute Summary

Attributes inherited from Abstract::LeasePool

#max_size

Method Summary

Methods included from Farce::Unshareable

#initialize, #ractor_shareable?

Methods inherited from Abstract::LeasePool

#available_count, #checked_out_count, #checkin, #checkout, #creating_count, #initialize, #size, #try_checkout

Methods included from Internal::Noncopyable

#duplicable?