Sha256: a0773ebd49de224428efb31e3cd1e320380aee827f550195138a0e8c40f23ab3

Contents?: true

Size: 515 Bytes

Versions: 1

Compression:

Stored size: 515 Bytes

Contents

module GluttonRatelimit
  
  class BurstyRingBuffer < ParentLimiter
    
    def oldest_timestamp
      @timestamps = Array.new executions, (Time.now - @time_period) if @timestamps.nil?
      @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-0.2.0 lib/glutton_ratelimit/bursty_ring_buffer.rb