Available on crate feature
blocking only.Expand description
The client without async: the same crate::Client driven by a private tokio runtime
(one worker thread), with blocking methods and plain-closure handlers.
use std::time::Duration;
use socketio_next::blocking::{Client, ClientBuilder};
use socketio_next::Event;
let client = ClientBuilder::new("http://localhost:3000")
.on("news", |event: Event, client: Client| {
println!("news: {:?}", event.payload());
client.emit("thanks", ()).ok();
})
.connect()?;
let reply = client.emit_with_ack("ping", (), Duration::from_secs(5))?;
client.disconnect()?;The blocking methods must not be called from inside an async runtime (tokio panics on a
nested block_on); handlers run on blocking threads, where they are fine.
Structsยง
- Client
- The blocking client. Cheap to clone; dropping the last clone the user holds disconnects
(bounded, as
Client::disconnect) and stops the runtime. The clients handed to handlers are for the duration of the call; do not keep them after the last user handle is gone. - Client
Builder - Builder of the blocking
Client; the options ofcrate::ClientBuilder.