Class: L2meter::ThreadSafe

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/l2meter/thread_safe.rb

Overview

This class is a wrapper around Emitter that makes sure that we have a completely separate clone of Emitter per thread running. It doesn’t truly make Emitter thread-safe, it makes sure that you don’t access the same instance of emitter from different threads.

Instance Method Summary collapse

Constructor Details

#initialize(emitter) ⇒ ThreadSafe

Returns a new instance of ThreadSafe.



31
32
33
# File 'lib/l2meter/thread_safe.rb', line 31

def initialize(emitter)
  @emitter = emitter.freeze
end

Instance Method Details

#context(*args, &block) ⇒ Object



37
38
39
40
# File 'lib/l2meter/thread_safe.rb', line 37

def context(*args, &block)
  value = current_emitter.context(*args, &block)
  Emitter === value ? clone_with_emitter(value) : value
end

#disable!Object



42
43
44
# File 'lib/l2meter/thread_safe.rb', line 42

def disable!
  @disabled = true
end