runScript method

  1. @override
Future<CommandResult> runScript(
  1. String script, {
  2. required bool showOutput,
})
override

Implementation

@override
Future<CommandResult> runScript(
  String script, {
  required bool showOutput,
}) async {
  final port = ReceivePort();

  final isolate = await Isolate.spawn(
    _runScript,
    port.sendPort,
  );

  final completer = Completer<CommandResult>();

  await for (final event in port) {
    if (event is SendPort) {
      event.send({
        'script': script,
        'showOutput': showOutput,
      });
    } else if (event is Map) {
      final result = CommandResult.fromJson(event);
      completer.complete(result);
      break;
    }
  }

  await completer.future;

  isolate.kill();

  return completer.future;
}