def flush()
      if defined? @@request and !@@request.nil?
        request_messages = []
        @lock.synchronize do
          request_messages = @messages
          @buffer.truncate(0)
          @messages = []
        end
        return if request_messages.empty?

        real = {
          e: 'ls',
          ls: request_messages,
        }.to_json

        @@request.body = real
        @response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: @uri.scheme == 'https') do |http|
          http.request(@@request)
        end

        # don't kill @task if this was executed from self.buffer
        # don't kill @task if there are queued messages
        unless @buffer_over_limit || @messages.any? || @task.nil?
          @task.shutdown
          @task.kill
        end
      end
    end
def flush()
      if defined? @@request and !@@request.nil?
        request_messages = []
        @lock.synchronize do
          request_messages = @messages
          @buffer.truncate(0)
          @messages = []
        end
        return if request_messages.empty?

        real = {
          e: 'ls',
          ls: request_messages,
        }.to_json

        @@request.body = real
        @response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: @uri.scheme == 'https') do |http|
          http.request(@@request)
        end

        # don't kill @task if this was executed from self.buffer
        # don't kill @task if there are queued messages
        unless @buffer_over_limit || @messages.any? || @task.nil?
          @task.shutdown
          @task.kill
        end
      end
    end
this should be running synchronously if @buffer_over_limit i.e. called from self.buffer
 else asynchronously through @task