DocLoader: Ensure the isolate has been properly started

It seems that sometimes _sendPort is null. I'm not sure why. In those
cases lets try to reinitialize the isolate.

Fixes APP-2W
This commit is contained in:
Vishesh Handa
2020-06-04 15:46:51 +02:00
parent 835bf1f089
commit 7d9cd6e63a

View File

@ -14,10 +14,14 @@ class MdYamlDocLoader {
var _loadingLock = Lock(); var _loadingLock = Lock();
Future<void> _initIsolate() async { Future<void> _initIsolate() async {
if (_isolate != null) return; if (_isolate != null && _sendPort != null) return;
return await _loadingLock.synchronized(() async { return await _loadingLock.synchronized(() async {
if (_isolate != null) return; if (_isolate != null && _sendPort != null) return;
if (_isolate != null) {
_isolate.kill(priority: Isolate.immediate);
_isolate = null;
}
_isolate = await Isolate.spawn(_isolateMain, _receivePort.sendPort); _isolate = await Isolate.spawn(_isolateMain, _receivePort.sendPort);
var data = await _receivePort.first; var data = await _receivePort.first;