Class: Moneta::Mutex

Inherits:
SynchronizePrimitive show all
Defined in:
lib/moneta/synchronize.rb

Overview

Distributed/shared store-wide mutex

Examples:

Use `Moneta::Mutex`

mutex = Moneta::Mutex.new(store, 'mutex')
mutex.synchronize do
  # Synchronized access
  store['counter'] += 1
end

Instance Method Summary collapse

Methods inherited from SynchronizePrimitive

#enter, #leave, #locked?, #synchronize, #try_enter

Constructor Details

#initialize(store, lock) ⇒ Mutex

Returns a new instance of Mutex

Parameters:

  • store (Moneta store)

    The store we want to lock

  • lock (Object)

    Key of the lock entry



75
76
77
78
# File 'lib/moneta/synchronize.rb', line 75

def initialize(store, lock)
  raise 'Store must support feature :create' unless store.supports?(:create)
  @store, @lock = store, lock
end