Class: ElasticAPM::Util::Throttle Private

Inherits:
Object
  • Object
show all
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

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

#callObject

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