Module: Redis::EM::Mutex::Macro

Defined in:
lib/redis/em-mutex/macro.rb

Overview

Macro-style definition

idea and some code borrowed from github.com/kenn/redis-mutex and enhanced

class ClassWithCriticalMethods

include Redis::EM::Mutex::Macro

auto_mutex
def critical
  ... do some critical stuff
  ....only one fiber in one process on one machine is executing this instance method of any instance of defined class
end

end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/redis/em-mutex/macro.rb', line 19

def self.included(klass)
  klass.extend ClassMethods
  klass.class_eval do
    class << self
      attr_reader :auto_mutex_methods, :auto_mutex_options
      attr_accessor :auto_mutex_enabled
    end
    @auto_mutex_methods = {}
    @auto_mutex_options = {:ns => Redis::EM::Mutex.ns ? "#{Redis::EM::Mutex.ns}:#{klass.name}" : klass.name}
    @auto_mutex_enabled = false
  end
end