Class: Farce::Unshared::Lease

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

Overview

A thread-safe lease that passes one resource directly within a Ractor.

Examples:

Updating one object from multiple threads

lease = Farce::Unshared::Lease.new { { count: 0 } }
workers = 3.times.map do
  Thread.new do
    lease.checkout { |state| state[:count] += 1 }
  end
end
workers.each(&:join)

lease.checkout { |state| state[:count] } # => 3

Method Summary

Methods included from Farce::Unshareable

#initialize, #ractor_shareable?

Methods inherited from Abstract::Lease

#available?, #checked_out?, #checkin, #checkout, #initialize, #owned?, #retire, #retired?, #try_checkout

Methods included from Internal::Noncopyable

#duplicable?