startApplication<T extends ApplicationChannel> function Null safety

Future startApplication<T extends ApplicationChannel>(
  1. Application<T> app,
  2. int isolateCount,
  3. SendPort parentPort
)

Implementation

Future startApplication<T extends ApplicationChannel>(
  Application<T> app,
  int isolateCount,
  SendPort parentPort,
) async {
  final port = ReceivePort();

  port.listen((msg) {
    if (msg["command"] == "stop") {
      port.close();
      app.stop().then((_) {
        parentPort.send({"status": "stopped"});
      });
    }
  });

  if (isolateCount == 0) {
    await app.startOnCurrentIsolate();
  } else {
    await app.start(numberOfInstances: isolateCount);
  }
  parentPort.send({"status": "ok", "port": port.sendPort});
}