class Berater::Lock
Attributes
capacity[R]
contention[R]
Public Class Methods
new(capacity, contention, release_fn = nil)
click to toggle source
# File lib/berater/lock.rb, line 6 def initialize(capacity, contention, release_fn = nil) @capacity = capacity @contention = contention @locked_at = Time.now @release_fn = release_fn @released_at = nil end
Public Instance Methods
locked?()
click to toggle source
# File lib/berater/lock.rb, line 14 def locked? @released_at.nil? end
release()
click to toggle source
# File lib/berater/lock.rb, line 18 def release raise 'lock already released' unless locked? @released_at = Time.now @release_fn&.call nil end