code: def flush(async=true)
        loop do
          @lock.synchronize do
            @queue.synchronize do
              @results_unprocessed += 1
            end
            @queue << @buffer
            @buffer = []
          end
          if not async
            LOGGER.info('Starting synchronous flush')
            @queue.synchronize do
              @all_processed_condition.wait_while { @results_unprocessed > 0 }
              LOGGER.info('Finished synchronous flush')
            end
          end
          break if @buffer.size < 1
        end
      end
docs: Flush the buffer
    If async is false, block until the queue is empty