pub struct Client { /* private fields */ }blocking only.Expand description
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.
Implementations§
Source§impl Client
impl Client
Sourcepub fn emit(
&self,
event: impl AsRef<str>,
data: impl Into<Payload>,
) -> Result<()>
pub fn emit( &self, event: impl AsRef<str>, data: impl Into<Payload>, ) -> Result<()>
See crate::Client::emit (never blocks).
Sourcepub fn emit_with_ack(
&self,
event: impl AsRef<str>,
data: impl Into<Payload>,
timeout: Duration,
) -> Result<Payload>
pub fn emit_with_ack( &self, event: impl AsRef<str>, data: impl Into<Payload>, timeout: Duration, ) -> Result<Payload>
See crate::Client::emit_with_ack; blocks until the ack, the timeout or the loss.
Sourcepub fn disconnect(&self) -> Result<()>
pub fn disconnect(&self) -> Result<()>
See crate::Client::disconnect; blocks (bounded).
Sourcepub fn reconnect(&self) -> Result<()>
pub fn reconnect(&self) -> Result<()>
See crate::Client::reconnect; blocks until the attempt ends.
Sourcepub fn on<F>(&self, event: impl Into<String>, handler: F) -> ListenerId
pub fn on<F>(&self, event: impl Into<String>, handler: F) -> ListenerId
Adds a handler for event.
Sourcepub fn once<F>(&self, event: impl Into<String>, handler: F) -> ListenerId
pub fn once<F>(&self, event: impl Into<String>, handler: F) -> ListenerId
Adds a handler for the next event.
Sourcepub fn on_any<F>(&self, handler: F) -> ListenerId
pub fn on_any<F>(&self, handler: F) -> ListenerId
Adds a handler for every event.
Sourcepub fn on_state_change<F>(&self, handler: F) -> ListenerId
pub fn on_state_change<F>(&self, handler: F) -> ListenerId
Adds a handler for every state transition.
Sourcepub fn off_listener(&self, id: ListenerId) -> bool
pub fn off_listener(&self, id: ListenerId) -> bool
Removes one handler.
Sourcepub fn listener_count(&self, event: &str) -> usize
pub fn listener_count(&self, event: &str) -> usize
Number of handlers of event.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
The current state.
Sourcepub fn wait_for(
&self,
predicate: impl Fn(&ConnectionState) -> bool,
timeout: Duration,
) -> ConnectionState
pub fn wait_for( &self, predicate: impl Fn(&ConnectionState) -> bool, timeout: Duration, ) -> ConnectionState
Blocks until the state matches predicate, the client closed, or timeout passed;
returns the state then.