class Google::Cloud::Bigquery::Table::AsyncInserter

def run_background

def run_background
  synchronize do
    until @stopped
      if @batch.nil?
        @cond.wait
        next
      end
      time_since_first_publish = ::Time.now - @batch_created_at
      if time_since_first_publish < @interval
        # still waiting for the interval to insert the batch...
        timeout = @interval - time_since_first_publish
        @cond.wait timeout
      else
        # interval met, insert the batch...
        push_batch_request!
        @cond.wait
      end
    end
  end
end