dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

how to spawn a thread in main or other place only once

Open jiker-burce opened this issue 1 year ago • 0 comments

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 the Client will 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

jiker-burce avatar May 05 '24 16:05 jiker-burce