Sha256: 84721cc3c08eff91c84c295b01b6c67d146e91ec8b353f3b1050b11b40b7b86e

Contents?: true

Size: 717 Bytes

Versions: 2

Compression:

Stored size: 717 Bytes

Contents

require 'rubygems'
require 'glutton_ratelimit'

class LimitInstanceMethods
  extend GluttonRatelimit
    
  def initialize
    @start = Time.now
  end
  
  def limit_me
    puts "#{Time.now - @start}"
    sleep 0.001
  end
  
  def cap_me
    puts "#{Time.now - @start}"
    sleep 0.001
  end
  
  rate_limit :limit_me, 6, 6
  rate_limit :cap_me, 6, 6, GluttonRatelimit::BurstyTokenBucket
end

t = LimitInstanceMethods.new

puts "Six requests every 6 seconds (Averaged): "
13.times { t.limit_me }
puts "Six requests every 6 seconds (Bursty): "
13.times { t.cap_me }

# In both cases:
# The 7th execution should occur after 6 seconds after the first.
# The 13th execution should occur after 12 seconds after the first.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glutton_ratelimit-1.0.0 examples/limit_instance_methods.rb
glutton_ratelimit-0.1.0 examples/limit_instance_methods.rb