run method

  1. @override
CommandExecution run(
  1. String command,
  2. String cwd
)
override

Implementation

@override
CommandExecution run(String command, String cwd) {
  final controller = StreamController<String>();
  final exit = Completer<int>();
  final out = _LineSink(controller.add);
  final err = _LineSink(controller.add);

  _client
      .executeStreaming(
        nodeId: _nodeId,
        command: command,
        cwd: cwd,
        shellFamily: shellFamily,
        onStdout: out.add,
        onStderr: err.add,
      )
      .then((code) {
        out.flush();
        err.flush();
        controller.close();
        if (!exit.isCompleted) exit.complete(code);
      })
      .catchError((Object e) {
        controller.addError(e);
        controller.close();
        if (!exit.isCompleted) exit.completeError(e);
      });

  // Remote exec has no cheap mid-flight cancel; kill is a best-effort no-op.
  return CommandExecution(
    output: controller.stream,
    exitCode: exit.future,
    kill: () {},
  );
}