`killAll()` sends the main isolate into an unknown state
frank06 opened this issue · 3 comments
frank06 commented
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterIsolate.killAll();
print('done');
// ...
}
The string "done" never gets printed, execution halted (but not paused) and with no exceptions.
Why do I want to kill all isolates when starting the app? Because my isolate is a long-running one (doesn't kill()
itself) and I don't want zombie isolates accumulating every time I hot restart. Flutter has no known callback to execute code just before a hot restart.
Versions:
flutter
: 2.10.3flutter_isolate
: ^2.0.2
frank06 commented
Found a workaround:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// ignore: unawaited_futures
FlutterIsolate.killAll();
Future.delayed(Duration(milliseconds: 100), () async {
print('done');
// ...
});
}
Deleted user commented
Same issue, I notice that even with isolate instance, isolate.kill(priority: Isolate.immediate); didn't work when isolate got a while / recursive inside... Kill not working.
nmfisher commented
These both look like the method channel just doesn't report back appopriately, looks easily fixable.