# File lib/aws/core/collection/simple.rb, line 39
        def each_batch options = {}, &block

          each_opts  = options.dup
          limit      = each_opts.delete(:limit)
          limit      = limit.to_i if limit
          next_token = each_opts.delete(:next_token)
          offset     = next_token ? next_token.to_i - 1 : 0
          total      = 0

          nil_or_next_token = nil

          batch = []
          _each_item(each_opts.dup) do |item|

            total += 1

            # skip until we reach our offset (derived from the "next token")
            next if total <= offset

            if limit

              if batch.size < limit
                batch << item
              else
                # allow _each_item to yield one more item than needed
                # so we can determine if we should return a "next token"
                nil_or_next_token = total
                break
              end

            else
              batch << item
            end

          end

          yield(batch)

          nil_or_next_token

        end