Sha256: 1b3a38f2c42571483fbc597504cbbed08eeab2b9dc0f27d4823704c0b0a041b0
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
require "forwardable" module L2meter # 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. class ThreadSafe extend Forwardable EMITTER_METHODS = %i[ batch configuration context count log measure push_context sample silence silence! unique unsilence! with_elapsed ] private_constant :EMITTER_METHODS def initialize(emitter) @emitter = emitter.freeze end def_delegators :receiver, *EMITTER_METHODS def disable! @disabled = true end private attr_reader :emitter def receiver @disabled ? null_emitter : current_emitter end def current_emitter Thread.current[thread_key] ||= emitter.clone end def null_emitter @null_emitter ||= NullObject.new end def thread_key @thread_key ||= "_l2meter_emitter_#{emitter.object_id}".freeze end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
l2meter-0.4.0 | lib/l2meter/thread_safe.rb |