run method

Future<void> run()

Equivalent to run that waits for SIGTERM/SIGABRT

Implementation

Future<void> run() async {
  await start();
  try {
    final term = Completer<void>();

    // SIGTERM
    final subTerm = ProcessSignal.sigterm.watch().listen((_) {
      if (!term.isCompleted) term.complete();
    });

    // SIGABRT (only on some platforms)
    StreamSubscription<ProcessSignal>? subAbort = ProcessSignal.sigabrt
        .watch()
        .listen((_) {
          if (!term.isCompleted) term.complete();
        });

    await term.future;

    await subTerm.cancel();
    await subAbort.cancel();
  } finally {
    await stop();
  }
}