flutter_isolate
flutter_isolate copied to clipboard
`killAll()` sends the main isolate into an unknown state
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.3 -
flutter_isolate
: ^2.0.2
Found a workaround:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// ignore: unawaited_futures
FlutterIsolate.killAll();
Future.delayed(Duration(milliseconds: 100), () async {
print('done');
// ...
});
}
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.
These both look like the method channel just doesn't report back appopriately, looks easily fixable.