You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Thanks for spending your time working on this library. It's great to see support for an asynchronous client.
Problem Description
Running the given example for the asynchronous client only works when not having an await statement within the callback. Code after the first await in the callback is not executed.
Thus, calling async functions is not possible.
When debugging, I found out that this is caused by the Stream implementation for the async client.
Connect with this Rust client and see that there is no output (note that "Connected!" will not be printed):
use futures_util::FutureExt;use log::info;use rust_socketio::{asynchronous::ClientBuilder,Event,TransportType};use std::time::Duration;use tokio::{
signal::{self,
unix::{signal,SignalKind},},
time::sleep,};#[tokio::main]asyncfnmain(){
env_logger::Builder::new().parse_default_env().init();info!("Starting");// get a socket that is connected to the admin namespacelet socket = ClientBuilder::new("http://localhost:4200/").transport_type(TransportType::Websocket).on(Event::Connect, |_payload, _client| {{asyncmove{sleep(Duration::from_secs(1)).await;info!("Connected!");}.boxed()}}).connect().await.expect("Connection failed");letmut sigterm = signal(SignalKind::terminate()).expect("unable to create sigterm signal");
tokio::select! {
_ = signal::ctrl_c() => {
info!("Received SIGINT, shutting down.");
},
_ = sigterm.recv() => {
info!("Received SIGTERM, shutting down.");
},
}
socket.disconnect().await.expect("Disconnect failed");}
Here's the corresponding Cargo.toml:
[package]
name = "client"version = "0.1.0"edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"rust_socketio = { version = "0.4.1-alpha.1", features = ["async"] }
env_logger = { version = "0.10" }
log = "0.4"tokio = { version = "1", features = ["macros", "rt", "signal", "time"] }
futures-util = "0.3"
It seems like the callback is aborted on the first await.
Possible Solution
Debugging around, I found that in the client's stream implementation, the ready! macro is used. This macro only returns the results of futures if they return immediately:
One possible solution I found was to use futures_util::stream::unfold in a new function on the Client instead of implementing stream (something like that):
Hi! Thanks for spending your time working on this library. It's great to see support for an asynchronous client.
Problem Description
Running the given example for the asynchronous client only works when not having an
await
statement within the callback. Code after the firstawait
in the callback is not executed.Thus, calling async functions is not possible.
When debugging, I found out that this is caused by the
Stream
implementation for the async client.Steps To Reproduce
Run this Python server:
Connect with this Rust client and see that there is no output (note that "Connected!" will not be printed):
Here's the corresponding Cargo.toml:
It seems like the callback is aborted on the first
await
.Possible Solution
Debugging around, I found that in the client's stream implementation, the
ready!
macro is used. This macro only returns the results of futures if they return immediately:rust-socketio/socketio/src/asynchronous/client/client.rs
Lines 410 to 441 in 10d5a46
One possible solution I found was to use
futures_util::stream::unfold
in a new function on theClient
instead of implementing stream (something like that):I created #314 as potential fix.
The text was updated successfully, but these errors were encountered: