Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restarting coroutines does not do anything #3004

Open
1 of 3 tasks
iwilare opened this issue Sep 26, 2024 · 0 comments · May be fixed by #3005
Open
1 of 3 tasks

Restarting coroutines does not do anything #3004

iwilare opened this issue Sep 26, 2024 · 0 comments · May be fixed by #3005
Labels
bug Something isn't working hooks Changes to built-in hook package

Comments

@iwilare
Copy link

iwilare commented Sep 26, 2024

Problem

Restarting a coroutine simply does not do anything, the coroutine does not get restarted. I have a MWE below.

Steps To Reproduce

Steps to reproduce the behavior:

  • Try compiling the following example:
use dioxus::prelude::*;
use dioxus_logger::tracing::{info, Level};

fn main() {
    dioxus_logger::init(Level::INFO).expect("");
    launch(App);
}

#[derive(Clone, Debug)]
enum S {
    SocketError,
    Connecting,
}

#[component]
fn AfterLogin(s: Signal<S>) -> Element {
    let mut ws_coroutine: Coroutine<()> = use_coroutine(|rx| async move {
        s.set(S::Connecting);
        for i in 0..5000 { info!("Computing..."); }
        s.set(S::SocketError);
    });
    match s() {
        S::SocketError => rsx! {
            button { onclick: move |e| {
                ws_coroutine.restart();
            }, "Try reconnecting" }
        },
        S::Connecting => rsx! {
            h1 { "ok" }
        },
    }
}

#[component]
fn App() -> Element {
    let mut connect: Signal<bool> = use_signal(|| false);
    let mut s: Signal<S> = use_signal(|| S::Connecting);
    rsx! {
        match connect() {
            true => rsx! { AfterLogin { s } },
            false => rsx! {
                div {
                    button { onclick: move |_| { connect.set(true); }, "Status {connect()})" }
                }
            }
        }
    }
}

Expected behavior

ws_coroutine should restart whenever the button is clicked.

Environment:

  • Dioxus version: 0.5.6
  • Rust version: 1.81.0
  • OS info: Debian (running in WSL2)
  • App platform: web

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@ealmloff ealmloff linked a pull request Sep 26, 2024 that will close this issue
@ealmloff ealmloff added bug Something isn't working hooks Changes to built-in hook package labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hooks Changes to built-in hook package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants