Struct workflow_websocket::client::WebSocket
source · [−]pub struct WebSocket { /* private fields */ }
Implementations
sourceimpl WebSocket
impl WebSocket
pub fn new(url: &str, settings: Settings) -> Result<WebSocket>
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 sender_tx<'ws>(&'ws self) -> &'ws Sender<DispatchMessage>
pub fn sender_tx<'ws>(&'ws self) -> &'ws Sender<DispatchMessage>
Returns reference to the transmission channel. You can clone the channel and use it directly. The channel sends DispatchMessage struct that has two values:
- DispatchMessage::Post(Message)
- DispatchMessage::WithAck(Message, Sender<Result<Arc<(),Arc<Error>>>)
To use WithAck message, you need to create an instance
of oneshot
channel and supply the sender, while retain
and await on receiver.recv() to get acknowledgement that
the message has been successfully handed off to the underlying
websocket.
sourcepub fn receiver_rx<'ws>(&'ws self) -> &'ws Receiver<Message>
pub fn receiver_rx<'ws>(&'ws self) -> &'ws 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.
sourcepub async fn send(&self, message: Message) -> Result<&Self, Arc<Error>>
pub async fn send(&self, message: Message) -> Result<&Self, Arc<Error>>
Sends a message to the destination server. This function will block until until the message was relayed to the underlying websocket implementation.
sourcepub async fn recv(&self) -> Result<Message>
pub async fn recv(&self) -> Result<Message>
Receives message from the websocket. Blocks until a message is received from the underlying websocket connection.
sourcepub fn inject_ctl(&self, ctl: Ctl) -> Result<()>
pub fn inject_ctl(&self, ctl: Ctl) -> Result<()>
Helper function that will relay a Ctl enum to the receiver
in the form of Message::Ctl(Ctl::*)
This should be called only with Ctl::Custom(u32) as other
control messages are issues by the underlying websocket implementation