init method
Implementation
Future<void> init() async {
var completer = Completer<void>();
receivePort = ReceivePort();
await Isolate.spawn(_entryPoint, receivePort.sendPort);
_portSubscription = receivePort.listen((Object? message) {
if (message is SendPort) {
_isolatePort = message;
completer.complete();
} else {
var task = message as IsolateTask<T, R>;
if (!_completers.containsKey(task.id)) {
throw StateError('Task ${task.id} not present.');
}
_completers[task.id]?.complete(task.result);
_completers.remove(task.id);
}
});
return completer.future;
}