Sha256: 21c6c9ad28e24410c2a94c8288f991d20f7d6429fbc4a39a72c574013a7133ef
Contents?: true
Size: 750 Bytes
Versions: 1
Compression:
Stored size: 750 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
glutton_ratelimit-0.2.0 | examples/limit_instance_methods.rb |