Skip to content

Instantly share code, notes, and snippets.

@stevenbarragan
Last active November 16, 2017 00:13
Show Gist options
  • Save stevenbarragan/7a3734914c78f8d7e80eea5084b91ad5 to your computer and use it in GitHub Desktop.
Save stevenbarragan/7a3734914c78f8d7e80eea5084b91ad5 to your computer and use it in GitHub Desktop.
class Throttler
def initialize(time_limit, &block)
@block = block
@created_at = Time.now
@time_limit = time_limit
@block.call()
end
def call
@block.call() if call_now?
end
def call_now?
Time.now > @created_at + @time_limit
end
end
function = Throttler.new(1) do
puts "Hello World"
end
function.call()
function.call()
function.call()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment