flutter_isolate icon indicating copy to clipboard operation
flutter_isolate copied to clipboard

Unable to locate Isolate to kill it

Open AhmadDanielD opened this issue 4 years ago • 1 comments

After spawning a new Isolate, it will continue to work even after the app is killed (tested), Example: void startIsolate() async { await FlutterIsolate.spawn(isolate1, "hello"); } void isolate1(String arg) { Timer.periodic(Duration(seconds:1),(timer)=>print("Hello")); } void stopIsolate(){ // what should be the code here? how to catch it after killing the app?

} The issue is after the app is relaunched the isolates keep on running, I'm unable to catch it anymore, is there a way to find the current running isolate (not the main)? FlutterIsolate.current returns the main isolate not isolate1, after killing the app, isolate1 only stops by going to mobile setting->appSetting-> force stop

AhmadDanielD avatar Dec 01 '21 11:12 AhmadDanielD

You can use the instance returned by await FlutterIsolate.spawn(isolate1, "hello"); and then call kill() on that.

The main problem would be: where do you call stopIsolate()?

I am using the killAll() API at app start, not without its problems: https://github.com/rmawatson/flutter_isolate/issues/107

frank06 avatar May 25 '22 19:05 frank06