def patiently(wait = 8, delay = 0.1)
      try_until = Time.now + wait
      failure   = nil

      while Time.now < try_until do
        begin
          return yield
        rescue Exception => e
          failure = e
          sleep delay
        end
      end
      failure ? (raise failure) : (raise TimeoutError)
    end
def patiently(wait = 8, delay = 0.1)
      try_until = Time.now + wait
      failure   = nil

      while Time.now < try_until do
        begin
          return yield
        rescue Exception => e
          failure = e
          sleep delay
        end
      end
      failure ? (raise failure) : (raise TimeoutError)
    end
Similar to `#poll`, `#patiently` also executes an arbitrary code block.
 If the passed block runs without raising an error, execution proceeds
 normally. If an error is raised, the block is rerun after a brief
 delay, until the block can be run without exceptions. If exceptions
 continue to raise, `#patiently` gives up after a bit (default 8
 seconds) by re-raising the most recent exception raised by the block.

 @example
   Returns immedialtely if no errors or as soon as error stops.
     patiently { ... }

   Increase patience to 10 seconds.
     patiently(10)    { ... }

   Increase patience to 20 seconds, and delay for 3 seconds before retry.
     patiently(20, 3) { ... }

 @param [Integer] seconds
   number of seconds to be patient, default is 8 seconds

 @param [Integer] delay
   seconds to wait after encountering a failure, default is 0.1 seconds

 @yield [Proc]
   A block that will be run, and if it raises an error, re-run until
   success, or patience runs out.

 @raise [Exception] the most recent Exception that caused the loop to
   retry before giving up.

 @return [Proc]
   the value of the passed block.

 @api public