on dispose kill isolate

This commit is contained in:
Dan Ballard 2021-02-09 11:56:09 -08:00
parent 1a59b72815
commit cbab08f072
1 changed files with 10 additions and 1 deletions

View File

@ -57,6 +57,8 @@ class CwtchFfi implements Cwtch {
ProfileListState profileCN;
CwtchNotifier cwtchNotifier;
Isolate cwtchIsolate;
CwtchFfi(ProfileListState profs) {
library = DynamicLibrary.open("libCwtch.so");
profileCN = profs;
@ -81,7 +83,7 @@ class CwtchFfi implements Cwtch {
// Test non timer getting events from libcwtch-go
var _receivePort = ReceivePort();
var _isolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort);
cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort);
_receivePort.listen((message) {
var env = jsonDecode(message);
cwtchNotifier.handleMessage(env["EventType"], env["Data"]);
@ -89,6 +91,13 @@ class CwtchFfi implements Cwtch {
//repaintProfileStream = pollRepaintProfileEvents();
}
@override
void dispose() {
if (cwtchIsolate != null) {
cwtchIsolate.kill();
}
}
/*
Stream<bool> GetRepaintProfileStream() {
return repaintProfileStream;