Skip to content

Commit

Permalink
Add details about tokio drop and rapid shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Jun 8, 2024
1 parent ae1ce8a commit 3cdddf3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions documentation/docs/graceful-shutdown.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Graceful Shutdown

When the Flutter app is closed, the entire `tokio` async runtime on the Rust side will be terminated automatically.
When the Flutter app is closed, the entire `tokio` async runtime on the Rust side will be terminated automatically. Even if the app is force-closed, the `tokio` async runtime will be properly dropped.

When using Rinf, the lifetime of the `tokio` runtime follows that of the Dart runtime. This behavior is different from typical `tokio` executables where its async runtime lives throughout the `main()` function of Rust.
When using Rinf, the lifetime of the `tokio` runtime follows that of the Dart runtime. This behavior is different from typical `tokio` executables where its async runtime lives throughout the async `main()` function of Rust.

In some cases, you might need to run some finalization code in Rust before the app closes. This might involve saving files or disposing of resources. To achieve this, you can use Flutter's `AppLifecycleListener` to run something or to get user confirmation before closing the Flutter app.

Expand Down Expand Up @@ -41,3 +41,7 @@ class _MyAppState extends State<MyApp> {
}
...
```

It's worth noting that `AppLifecycleListener` or `dispose` cannot always be relied upon for app closings. Below is a text snippet quoted from the official [Flutter docs](https://api.flutter.dev/flutter/widgets/State/dispose.html):

> There is no way to predict when application shutdown will happen. For example, a user's battery could catch fire, or the user could drop the device into a swimming pool, or the operating system could unilaterally terminate the application process due to memory pressure. Applications are responsible for ensuring they behave well even in the face of rapid, unscheduled termination.

0 comments on commit 3cdddf3

Please sign in to comment.