Class: Sqreen::Ecosystem::Tracing::Sampler::MaxCallsPrimitive
- Inherits:
-
Object
- Object
- Sqreen::Ecosystem::Tracing::Sampler::MaxCallsPrimitive
- Defined in:
- lib/sqreen/ecosystem/tracing/sampler.rb
Instance Method Summary collapse
-
#initialize(max_calls) ⇒ MaxCallsPrimitive
constructor
A new instance of MaxCallsPrimitive.
- #triggers? ⇒ Boolean
Constructor Details
#initialize(max_calls) ⇒ MaxCallsPrimitive
Returns a new instance of MaxCallsPrimitive.
138 139 140 141 142 143 |
# File 'lib/sqreen/ecosystem/tracing/sampler.rb', line 138 def initialize(max_calls) @max_calls = max_calls @disabled = false # to avoid lock @mutex = Mutex.new @num_calls = 0 end |
Instance Method Details
#triggers? ⇒ Boolean
145 146 147 148 149 150 151 152 |
# File 'lib/sqreen/ecosystem/tracing/sampler.rb', line 145 def triggers? return false if @disabled num_calls = @mutex.synchronize do @num_calls += 1 end num_calls <= @max_calls end |