Struct workflow_websocket::client::WebSocket
source · pub struct WebSocket { /* private fields */ }
Expand description
An async WebSocket implementation capable of operating uniformly under a browser-backed executor in WASM and under native tokio-runtime.
Implementations§
source§impl WebSocket
impl WebSocket
sourcepub fn new(url: &str, options: Options) -> Result<WebSocket>
pub fn new(url: &str, options: Options) -> Result<WebSocket>
Create a new WebSocket instance connecting to the given URL.
sourcepub fn set_url(&self, url: &str)
pub fn set_url(&self, url: &str)
Changes WebSocket connection URL.
Following this call, you must invoke
WebSocket::reconnect().await
manually
sourcepub fn receiver_rx(&self) -> &Receiver<Message>
pub fn receiver_rx(&self) -> &Receiver<Message>
Returns the reference to the Receiver channel
sourcepub async fn connect(
&self,
block_until_connected: bool
) -> Result<Option<Listener>>
pub async fn connect( &self, block_until_connected: bool ) -> Result<Option<Listener>>
Connects the websocket to the destination URL.
Optionally accepts block_until_connected
argument
that will block the async execution until the websocket
is connected.
Once invoked, connection task will run in the background and will attempt to repeatedly reconnect if the websocket connection is closed.
To suspend reconnection, you have to call disconnect()
method explicitly.
sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnects the websocket from the destination server.
sourcepub async fn reconnect(&self) -> Result<()>
pub async fn reconnect(&self) -> Result<()>
Trigger WebSocket to reconnect. This method closes the underlying WebSocket connection causing the WebSocket implementation to re-initiate connection.
sourcepub async fn post(&self, message: Message) -> Result<&Self>
pub async fn post(&self, message: Message) -> Result<&Self>
Sends a message to the destination server. This function will queue the message on the relay channel and return successfully if the message has been queued. This function enforces async yield in order to prevent potential blockage of the executor if it is being executed in tight loops.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for WebSocket
impl Send for WebSocket
impl Sync for WebSocket
impl Unpin for WebSocket
impl !UnwindSafe for WebSocket
Blanket Implementations§
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.