class Sass::Compiler::Connection

It runs the ‘sass –embedded` command.
The stdio based {Connection} between the {Dispatcher} and the compiler.

def close

def close
  @mutex.synchronize do
    @stdin.close
    @wait_thread.join
    @stdout.close
    @stderr.close
  end
end

def closed?

def closed?
  @mutex.synchronize do
    @stdin.closed? && !@wait_thread.alive?
  end
end

def id

def id
  @wait_thread.pid
end

def initialize

def initialize
  @mutex = Mutex.new
  @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*CLI::COMMAND, '--embedded', chdir: __dir__)
  @stdin.binmode
  # # https://dart.dev/tools/dart-devtools
  # if 'dart' == File.basename(CLI::COMMAND.first, '.exe') && CLI::COMMAND.include?('--observe')
  #   Kernel.warn(@stdout.readline, uplevel: 0)
  #   Kernel.warn(@stdout.readline, uplevel: 0)
  # end
  @stdout.binmode
  @wait_thread.name = "sass-embedded-process-waiter-#{id}"
end

def listen(dispatcher)

def listen(dispatcher)
  Thread.new do
    Thread.current.name = "sass-embedded-process-stdout-poller-#{id}"
    loop do
      length = Varint.read(@stdout)
      id = Varint.read(@stdout)
      proto = @stdout.read(length - Varint.length(id))
      dispatcher.receive_proto(id, proto)
    end
  rescue IOError, Errno::EBADF, Errno::EPROTO => e
    dispatcher.error(e)
    @mutex.synchronize do
      @stdout.close
    end
  end
  Thread.new do
    Thread.current.name = "sass-embedded-process-stderr-poller-#{id}"
    loop do
      Kernel.warn(@stderr.readline, uplevel: 0)
    end
  rescue IOError, Errno::EBADF
    @mutex.synchronize do
      @stderr.close
    end
  end
end

def write(id, proto)

def write(id, proto)
  buffer = []
  Varint.write(buffer, Varint.length(id) + proto.length)
  Varint.write(buffer, id)
  @mutex.synchronize do
    @stdin.write(buffer.pack('C*'), proto)
  end
end