def tail(options = {})
      q = []
      event_id_highwater = nil
      counter = 0
      number = options[:number] || 0
      for_each_event name do |fetched_event|
        q.unshift fetched_event if counter < number
        counter = counter + 1
      end

      while q.size > 0
        event = q.shift
        yield event
        event_id_highwater = event.event_id
      end

      sleep_time = 1

      running = true
      if options[:follow]
        while running
          sleep_time = [sleep_time * (options[:backoff] || 1), options[:backoff_max_wait] || 15].min
          begin
            stack_status = describe_stacks(stack_name: name).stacks.first.stack_status
            running = running && (/.+_(COMPLETE|FAILED)$/.match(stack_status) == nil)

            yielding = true
            for_each_event name do |fetched_event|
              if event_id_highwater == fetched_event.event_id
                yielding = false
              end

              if yielding
                q.unshift fetched_event
              end
            end
          rescue Aws::CloudFormation::Errors::Throttling
            Cfer::LOGGER.debug "AWS SDK is being throttled..."
            # Keep going though.
          rescue Aws::CloudFormation::Errors::ValidationError
            running = false
          end

          while q.size > 0
            event = q.shift
            yield event
            event_id_highwater = event.event_id
            sleep_time = 1
          end

          sleep sleep_time if running unless options[:no_sleep]
        end
      end
    end
def tail(options = {})
      q = []
      event_id_highwater = nil
      counter = 0
      number = options[:number] || 0
      for_each_event name do |fetched_event|
        q.unshift fetched_event if counter < number
        counter = counter + 1
      end

      while q.size > 0
        event = q.shift
        yield event
        event_id_highwater = event.event_id
      end

      sleep_time = 1

      running = true
      if options[:follow]
        while running
          sleep_time = [sleep_time * (options[:backoff] || 1), options[:backoff_max_wait] || 15].min
          begin
            stack_status = describe_stacks(stack_name: name).stacks.first.stack_status
            running = running && (/.+_(COMPLETE|FAILED)$/.match(stack_status) == nil)

            yielding = true
            for_each_event name do |fetched_event|
              if event_id_highwater == fetched_event.event_id
                yielding = false
              end

              if yielding
                q.unshift fetched_event
              end
            end
          rescue Aws::CloudFormation::Errors::Throttling
            Cfer::LOGGER.debug "AWS SDK is being throttled..."
            # Keep going though.
          rescue Aws::CloudFormation::Errors::ValidationError
            running = false
          end

          while q.size > 0
            event = q.shift
            yield event
            event_id_highwater = event.event_id
            sleep_time = 1
          end

          sleep sleep_time if running unless options[:no_sleep]
        end
      end
    end
Yields to the given block for each CloudFormation event that qualifies, given the specified options.
 @param options [Hash] The options hash
 @option options [Fixnum] :number The maximum number of already-existing CloudFormation events to yield.
 @option options [Boolean] :follow Set to true to wait until the stack enters a `COMPLETE` or `FAILED` state, yielding events as they occur.
 @option options [Boolean] :no_sleep Don't pause between polling. This is used for tests, and shouldn't be when polling the AWS API.
 @option options [Fixnum] :backoff The exponential backoff factor (default 1.5)
 @option options [Fixnum] :backoff_max_wait The maximum amount of time that exponential backoff will wait before polling agian (default 15s)