robj
only.Expand description
Lazy transmission of values.
This allows a remote endpoint to optionally request the transmission of a value. For example, a client may only be interested sometimes in the value of a field of a larger struct. By wrapping the value of this field in a Lazy, the value of the field is not initially transmitted with the struct, but the client can request it by calling Lazy::get if interested. While this can save transmission bandwidth the drawback is an additional delay of the connection round-trip time when the lazy value is requested.
This can be forwarded over multiple remote endpoints.
§Example
In the following example the client sends a message to the server.
The value of the field big_data
is not initially transmitted, but
retrieved when the server calls get()
on it.
use remoc::prelude::*;
use remoc::robj::lazy::Lazy;
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Msg {
data: u32,
big_data: Lazy<String>,
}
// This would be run on the client.
async fn client(mut tx: rch::base::Sender<Msg>) {
let msg = Msg { data: 123, big_data: Lazy::new("long data".to_string()) };
tx.send(msg).await.unwrap();
}
// This would be run on the server.
async fn server(mut rx: rch::base::Receiver<Msg>) {
let msg = rx.recv().await.unwrap().unwrap();
assert_eq!(msg.data, 123);
assert_eq!(*msg.big_data.get().await.unwrap(), "long data");
}
Structs§
- Lazy value.
- Lazy provider.
- A reference to a lazily received value.
Enums§
- An error occurred during fetching a lazily transmitted value.