Module: Ohm::Locking

Defined in:
lib/ohm/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

#spinlock(wait = 0.1) ⇒ Object

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

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

15
16
17
18
19
20
# File 'lib/ohm/locking.rb', line 15

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