This is a discussion from egui, which started one year ago.
I'm not familiar with GUI programming or async code. And I get four patterns from that discussion:
- Use a thread to run tokio runtime, and the runtime spawns async tasks, like this. But this approch seems to run tasks only in that function.
- Use a thread to run tokio runtime globally, and call
tokio::spawn
whenever an async task is required. Like this: it looks good. - Run egui on tokio runtime, like this.
- Carry the tokio runtime in the top struct which is implemented with
::eframe::App
trait, like this.
I have no idea which design is the best and how good or bad they are.