mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
MdYamlDocLoader: Avoid starting the isolate multiple times
Man, there is a lot of locking that I hadn't even thought of while writing all of this code.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:synchronized/synchronized.dart';
|
||||
|
||||
import 'package:gitjournal/core/md_yaml_doc.dart';
|
||||
import 'package:gitjournal/core/md_yaml_doc_codec.dart';
|
||||
|
||||
@ -9,13 +11,19 @@ class MdYamlDocLoader {
|
||||
ReceivePort _receivePort = ReceivePort();
|
||||
SendPort _sendPort;
|
||||
|
||||
var _loadingLock = Lock();
|
||||
|
||||
Future<void> _initIsolate() async {
|
||||
if (_isolate != null) return;
|
||||
|
||||
return await _loadingLock.synchronized(() async {
|
||||
if (_isolate != null) return;
|
||||
_isolate = await Isolate.spawn(_isolateMain, _receivePort.sendPort);
|
||||
|
||||
var data = await _receivePort.first;
|
||||
assert(data is SendPort);
|
||||
_sendPort = data as SendPort;
|
||||
});
|
||||
}
|
||||
|
||||
Future<MdYamlDoc> loadDoc(String filePath) async {
|
||||
|
@ -640,6 +640,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.5"
|
||||
synchronized:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: synchronized
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -36,6 +36,7 @@ dependencies:
|
||||
connectivity: ^0.4.6+1
|
||||
flutter_emoji: ">= 2.0.0"
|
||||
git_url_parse2: ^0.0.1
|
||||
synchronized: ^2.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.2"
|
||||
|
Reference in New Issue
Block a user