Module: EventStoreSubscriptions::MakeAtomic

Included in:
Subscription, Subscriptions
Defined in:
lib/event_store_subscriptions/make_atomic.rb

Instance Method Summary collapse

Instance Method Details

#make_atomic(method) ⇒ Symbol

Wraps method in Mutex#synchronize to make it atomic. You should have #semaphore method implemented in order this to work.

Parameters:

  • method (Symbol)

    a name of the method

Returns:

  • (Symbol)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/event_store_subscriptions/make_atomic.rb', line 9

def make_atomic(method)
  module_to_prepend = Module.new do
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def #{method}(*args, **kwargs, &blk)
      semaphore.synchronize do
        super
      end
    end
    RUBY
  end
  prepend module_to_prepend
  method
end