Sha256: 4f6da91e63cee652f3ab7bd63a22670dca144d9c5c110e154c44adeeda387c7b

Contents?: true

Size: 463 Bytes

Versions: 1

Compression:

Stored size: 463 Bytes

Contents

module GluttonRatelimit
  
  class BurstyTokenBucket < ParentLimiter
    
    def reset_bucket
      @oldest_timestamp = Time.now
      @tokens = @executions
    end
    
    def wait
      reset_bucket if @tokens.nil?
      
      if @tokens.zero?
        delta = Time.now - @oldest_timestamp
        sleep(@time_period - delta) if delta < @time_period
        reset_bucket
      end
      
      @tokens -= 1
    end
    
  end

end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glutton_ratelimit-0.2.0 lib/glutton_ratelimit/bursty_token_bucket.rb