Skip to content
Discussion options

You must be logged in to vote

Dioxus runs async tasks on the main thread by default. If you want to run an expensive task you can use another thread or a tokio task.

If your real task is blocking, I would recommend using a new thread. If you change the task in your example to be async, it should work:

fn WhyBlockingEffect(cx: Scope) -> Element {
    let token = use_state(cx, || None);

    use_effect(cx, (token,), |(token,)| {
        to_owned![token];

        async move {
            // Background task, might take a long time to complete.
            if token.get().is_some() {
                tokio::time::sleep(Duration::from_secs(5)).await;
                token.set(None);
            }
        }
    });

    let s…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@clouds56
Comment options

@ealmloff
Comment options

Answer selected by bellwether-softworks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants