Struct holochain_websocket::WebsocketSender
source · [−]pub struct WebsocketSender { /* private fields */ }
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
sourceimpl WebsocketSender
impl WebsocketSender
sourcepub 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.
sourcepub 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
.
sourcepub 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
sourceimpl Clone for WebsocketSender
impl Clone for WebsocketSender
sourcefn clone(&self) -> WebsocketSender
fn clone(&self) -> WebsocketSender
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more