Class: L2meter::ThreadSafe
- Inherits:
-
Object
- Object
- L2meter::ThreadSafe
- 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
- #context(*args, &block) ⇒ Object
- #disable! ⇒ Object
-
#initialize(emitter) ⇒ ThreadSafe
constructor
A new instance of ThreadSafe.
Constructor Details
#initialize(emitter) ⇒ ThreadSafe
Returns a new instance of ThreadSafe.
28 29 30 |
# File 'lib/l2meter/thread_safe.rb', line 28 def initialize(emitter) @emitter = emitter.freeze end |
Instance Method Details
#context(*args, &block) ⇒ Object
34 35 36 37 |
# File 'lib/l2meter/thread_safe.rb', line 34 def context(*args, &block) value = current_emitter.context(*args, &block) Emitter === value ? clone_with_emitter(value) : value end |
#disable! ⇒ Object
39 40 41 |
# File 'lib/l2meter/thread_safe.rb', line 39 def disable! @disabled = true end |