Sha256: 42a288e742af8123f085d0840fd9cf777dbba83d9364a465542947294c2016fe

Contents?: true

Size: 437 Bytes

Versions: 1

Compression:

Stored size: 437 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.1.0 lib/glutton_ratelimit/bursty_token_bucket.rb