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.



29
30
31
# File 'lib/l2meter/thread_safe.rb', line 29

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

Instance Method Details

#context(*args, &block) ⇒ Object



35
36
37
38
# File 'lib/l2meter/thread_safe.rb', line 35

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

#disable!Object



40
41
42
# File 'lib/l2meter/thread_safe.rb', line 40

def disable!
  @disabled = true
end