dioxus
dioxus copied to clipboard
how to spawn a thread in main or other place only once
Problem
Steps To Reproduce
Steps to reproduce the behavior:
fn main() {
launch(client_mod::client_lib::Client);
}
pub fn Client() -> Element {
println!("Client");
spawn(async move {
// do some async things here
}
}
- I found that if something changed, the
Client(main App component)will be rendered again, so theClientwill be printed many times. So that the spawn will generate many times.
Expected behavior
Is there a way could spawn new thread in fn main or other places, so I could just spawn a new thread once just like launch().
Screenshots
If applicable, add screenshots to help explain your problem.
Environment:
- Dioxus version: 0.5.1
- Rust version: 1.7.75
- OS info: MacOS
- App platform:
desktop