Struct holochain_websocket::WebsocketSender [−][src]
pub struct WebsocketSender { /* fields omitted */ }
Expand description
The sender half of an active connection.
Example
use holochain_serialized_bytes::prelude::*;
use holochain_websocket::*;
use std::time::Duration;
use url2::url2;
#[derive(serde::Serialize, serde::Deserialize, SerializedBytes, Debug)]
struct TestMessage(pub String);
#[tokio::main]
async fn main() {
let (mut send, _) = connect(
url2!("ws://127.0.0.1:12345"),
std::sync::Arc::new(WebsocketConfig::default()),
)
.await
.unwrap();
send.signal(TestMessage("Hey".to_string())).await.unwrap();
let resp: TestMessage = send.request(TestMessage("Hey".to_string())).await.unwrap();
println!("Got {:?}", resp);
match send
.request_timeout(TestMessage("Hey".to_string()), Duration::from_secs(1))
.await
{
Ok(r) => {
let resp: TestMessage = r;
println!("Got {:?}", resp);
}
Err(WebsocketError::RespTimeout) => eprintln!("Failed to get a response in 1 second"),
Err(e) => eprintln!("Got an error sending a request {:?}", e),
}
}
Implementations
pub async fn request_timeout<I, O>(
&mut self,
msg: I,
timeout: Duration
) -> WebsocketResult<O> where
I: Debug,
O: Debug,
WebsocketError: From<SerializedBytesError>,
I: Serialize,
O: DeserializeOwned,
pub async fn request_timeout<I, O>(
&mut self,
msg: I,
timeout: Duration
) -> WebsocketResult<O> where
I: Debug,
O: Debug,
WebsocketError: From<SerializedBytesError>,
I: Serialize,
O: DeserializeOwned,
Make a request to for the other side to respond to.
pub async fn request<I, O>(&mut self, msg: I) -> WebsocketResult<O> where
I: Debug,
O: Debug,
WebsocketError: From<SerializedBytesError>,
I: Serialize,
O: DeserializeOwned,
pub async fn request<I, O>(&mut self, msg: I) -> WebsocketResult<O> where
I: Debug,
O: Debug,
WebsocketError: From<SerializedBytesError>,
I: Serialize,
O: DeserializeOwned,
Make a request to for the other side to respond to.
Note:
There is no timeouts in this code. You either need to wrap
this future in a timeout or use WebsocketSender::request_timeout
.
pub async fn signal<I, E>(&mut self, msg: I) -> WebsocketResult<()> where
I: Debug,
WebsocketError: From<E>,
SerializedBytes: TryFrom<I, Error = E>,
pub async fn signal<I, E>(&mut self, msg: I) -> WebsocketResult<()> where
I: Debug,
WebsocketError: From<E>,
SerializedBytes: TryFrom<I, Error = E>,
Send a message to the other side that doesn’t require a response.
There is no guarantee this message will arrive. If you need confirmation
of receipt use WebsocketSender::request
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for WebsocketSender
impl Send for WebsocketSender
impl Sync for WebsocketSender
impl Unpin for WebsocketSender
impl !UnwindSafe for WebsocketSender
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more