Module: Ohm::Locking

Defined in:
lib/ohm/contrib/locking.rb

Overview

This module is a straight extraction from Ohm. The only difference is that this allows for a custom sleep value.

In addition, since future ohm versions might drop mutexes, I thought it might be a good idea to preseve this feature as a drop-in module.

Instance Method Summary collapse

Instance Method Details

#mutex(wait = 0.1) ⇒ Object

Lock the object before executing the block, and release it once the block is done.

Examples:


post = Order.create(:customer => Customer.create)
post.mutex(0.01) do
  # this block is in a mutex!
end


17
18
19
20
21
22
23
# File 'lib/ohm/contrib/locking.rb', line 17

def mutex(wait = 0.1)
  lock!(wait)
  yield
  self
ensure
  unlock!
end