Class: Redis::EM::Mutex::NS
- Inherits:
-
Object
- Object
- Redis::EM::Mutex::NS
- Defined in:
- lib/redis/em-mutex/ns.rb
Instance Attribute Summary collapse
-
#ns ⇒ Object
(also: #namespace)
readonly
Returns the value of attribute ns.
Instance Method Summary collapse
-
#initialize(ns, opts = {}) ⇒ NS
constructor
Creates a new namespace (Mutex factory).
-
#lock(*args) ⇒ Object
Attempts to grab the lock and waits if it isn’t available.
-
#new(*args) ⇒ Object
Creates a namespaced cross machine/process/fiber semaphore.
-
#synchronize(*args, &block) ⇒ Object
Executes block of code protected with namespaced semaphore.
Constructor Details
#initialize(ns, opts = {}) ⇒ NS
Creates a new namespace (Mutex factory).
-
ns = namespace
-
opts = options hash:
-
:block - default block timeout
-
:expire - default expire timeout
13 14 15 16 |
# File 'lib/redis/em-mutex/ns.rb', line 13 def initialize(ns, opts = {}) @ns = ns @opts = (opts || {}).merge(:ns => ns) end |
Instance Attribute Details
#ns ⇒ Object (readonly) Also known as: namespace
Returns the value of attribute ns.
5 6 7 |
# File 'lib/redis/em-mutex/ns.rb', line 5 def ns @ns end |
Instance Method Details
#lock(*args) ⇒ Object
Attempts to grab the lock and waits if it isn’t available.
See: Redis::EM::Mutex.lock
33 34 35 36 |
# File 'lib/redis/em-mutex/ns.rb', line 33 def lock(*args) mutex = new(*args) mutex if mutex.lock end |
#new(*args) ⇒ Object
Creates a namespaced cross machine/process/fiber semaphore.
for arguments see: Redis::EM::Mutex.new
21 22 23 24 25 26 27 28 |
# File 'lib/redis/em-mutex/ns.rb', line 21 def new(*args) if args.last.kind_of?(Hash) args[-1] = @opts.merge(args.last) else args.push @opts end Redis::EM::Mutex.new(*args) end |
#synchronize(*args, &block) ⇒ Object
Executes block of code protected with namespaced semaphore.
See: Redis::EM::Mutex.synchronize
41 42 43 |
# File 'lib/redis/em-mutex/ns.rb', line 41 def synchronize(*args, &block) new(*args).synchronize(&block) end |