init method

Future<void> init()

Implementation

Future<void> init() async {
  if (_isolate != null) return;

  _receivePort = ReceivePort();
  _isolate = await Isolate.spawn(_isolateEntryPoint, _receivePort!.sendPort);

  final completer = Completer<SendPort>();

  _receivePort!.listen((message) {
    if (message is SendPort) {
      completer.complete(message);
    } else if (message is IsolateResponse) {
      _handleResponse(message);
    }
  });

  _sendPort = await completer.future;
}