onStart method
Called when this service is registered with a ZenithRef.
Implementation
@override
Future<void> onStart(ZenithRef ref) async {
_receivePort = ReceivePort();
_subscription = _receivePort!.listen((message) {
if (message is T && onData != null) {
onData!(message);
}
});
final spawnedIsolate = await Isolate.spawn(
entryPoint,
_receivePort!.sendPort,
);
if (_receivePort == null) {
// Scope was disposed while Isolate.spawn was awaiting in flight
spawnedIsolate.kill(priority: Isolate.immediate);
return;
}
_isolate = spawnedIsolate;
}