Sha256: 4bdb22fcd848551a04acf9d5e1ab947d57bf12bb3d8109bf958240603a5c315c

Contents?: true

Size: 474 Bytes

Versions: 1

Compression:

Stored size: 474 Bytes

Contents

module GluttonRatelimit
  
  class BurstyRingBuffer < ParentLimiter
    
    def oldest_timestamp
      @timestamps ||= Array.new executions, (Time.now - @time_period) 
      @timestamps[0]
    end
    
    def current_timestamp= new_stamp
      @timestamps.push(new_stamp).shift
    end
      
    def wait
      delta = Time.now - oldest_timestamp
      sleep(@time_period - delta) if delta < @time_period
      self.current_timestamp = Time.now
    end
    
  end

end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glutton_ratelimit-1.0.0 lib/glutton_ratelimit/bursty_ring_buffer.rb