Module: Berater::Mutex

Defined in:
lib/berater/mutex.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extend_object(base) ⇒ Object



24
25
26
# File 'lib/berater/mutex.rb', line 24

def self.extend_object(base)
  included(base)
end

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/berater/mutex.rb', line 3

def self.included(base)
  # add class methods
  base.instance_eval do
    def synchronize(subkey = nil, **opts, &block)
      key = [ 'Mutex', name&.delete(':') || object_id, subkey ].compact.join(':')

      Berater::ConcurrencyLimiter(key, 1, **mutex_options.merge(opts)) do
        yield if block_given?
      end
    end

    def mutex_options(**kwargs)
      (@mutex_options ||= {}).update(kwargs)
    end
  end
end

Instance Method Details

#synchronizeObject



20
21
22
# File 'lib/berater/mutex.rb', line 20

def synchronize(...)
  self.class.synchronize(...)
end