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 "    def \#{method}(*args, **kwargs, &blk)\n      semaphore.synchronize do\n        super\n      end\n    end\n    RUBY\n  end\n  prepend module_to_prepend\n  method\nend\n", __FILE__, __LINE__ + 1