LiveProcess constructor

LiveProcess({
  1. required Stream<List<int>> stdout,
  2. required Stream<List<int>> stderr,
  3. required bool signal(
    1. ProcessSignal signal
    ),
})

Creates a LiveProcess reading stdout and stderr, and sending signals with signal.

Implementation

LiveProcess({
  required Stream<List<int>> stdout,
  required Stream<List<int>> stderr,
  required this._signal,
}) {
  int open = 2;
  void closed() {
    if (--open > 0) return;
    if (!_exited.isCompleted) _exited.complete();
    _lines.close();
  }

  for (final Stream<List<int>> stream in [stdout, stderr]) {
    stream
        .transform(const Utf8Decoder(allowMalformed: true))
        .transform(const LineSplitter())
        .listen(
          (String line) {
            output.add(line);
            _lines.add(line);
          },
          onError: (Object _) {},
          onDone: closed,
        );
  }
}