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

Can't handle server disconnecting? #282

Open
BWStearns opened this issue Feb 27, 2023 · 0 comments
Open

Can't handle server disconnecting? #282

BWStearns opened this issue Feb 27, 2023 · 0 comments

Comments

@BWStearns
Copy link

I was testing a case where the server shut down mid-session and my client outputted the error below (four times), but doesn't panic. There isn't an obvious place to handle the error since EngineIO Error isn't the type of any of the return values of methods I call. Is there some way to add a handler for unexpected disconnects?

Error: String(
    "EngineIO Error",
)

The code below is the setup.

    loop {
        let (is_done, rx) = mpsc::channel();
        let handler = make_response_handler(is_done);
        give_prompt();
        let input = get_input();
        let socket = ClientBuilder::new("http://localhost:3000")
            .on("search", handler)
            .on("error", |err, _| eprintln!("Error: {:#?}", err))
            .connect()
            .expect("Connection failed");
        let _result = socket
            .emit("search", json!({ "query": input }))
            .expect("Failed to emit");
        // Block on a channel waiting for the handler to signal completion, would like to send `_is_done` on server disconnect.
        let _is_done = rx.recv();
        // Never gets down here because still waiting on the server which has disconnected.
        println!("Made it past blocking!");
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant