Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created March 13, 2012 21:55
Show Gist options
  • Select an option

  • Save baroquebobcat/2032013 to your computer and use it in GitHub Desktop.

Select an option

Save baroquebobcat/2032013 to your computer and use it in GitHub Desktop.
Evil?
# Evil Exponential Backoff
#
# fog has this wait_for method that calls #to_f on its interval each iteration
# to determine how to sleep. https://github.com/fog/fog/blob/master/lib/fog/core/wait_for.rb
#
# This object will generate the 2**n series. Each time you call to_f, it'll give you another one.
#
iter = (0..(1/0.0)).each
def iter.to_f
2**self.next
end
p iter.to_f
# => 1
p iter.to_f
# => 2
p iter.to_f
# => 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment