Skip to content

Instantly share code, notes, and snippets.

@antaz
Created July 26, 2023 15:55
Show Gist options
  • Select an option

  • Save antaz/78382e64dac62cf6e4c5e2cf2615df40 to your computer and use it in GitHub Desktop.

Select an option

Save antaz/78382e64dac62cf6e4c5e2cf2615df40 to your computer and use it in GitHub Desktop.
Throttle for IIRC
module IIRC
module Throttle
# ratio in seconds / messages
def throttle_ratio
1/1r
end
def time
@time ||= Time.now
end
module Verbs
def msg(target, msg)
sleep(throttle_ratio) while (Time.now - time) <= throttle_ratio
super
@time = Time.now
end
alias :say :msg
end
include Verbs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment