Class: ElasticAPM::Util::Throttle Private
- Inherits:
-
Object
- Object
- ElasticAPM::Util::Throttle
- Defined in:
- lib/elastic_apm/util/throttle.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Usage example:
Throttle.new(5) { thing to only do once per 5 secs }
Instance Method Summary collapse
- #call ⇒ Object private
-
#initialize(buffer_secs, &block) ⇒ Throttle
constructor
private
A new instance of Throttle.
Constructor Details
#initialize(buffer_secs, &block) ⇒ Throttle
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Throttle.
27 28 29 30 |
# File 'lib/elastic_apm/util/throttle.rb', line 27 def initialize(buffer_secs, &block) @buffer_secs = buffer_secs @block = block end |
Instance Method Details
#call ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 39 |
# File 'lib/elastic_apm/util/throttle.rb', line 32 def call if @last_call && seconds_since_last_call < @buffer_secs return @last_result end @last_call = now @last_result = @block.call end |