pub struct Stream<T: RpcType + Send> { /* private fields */ }Expand description
A streaming procedure call.
Stream<T> is created by calling any procedure with the
_stream() suffix. This will start the stream
automatically.
This type provides access to the procedure’s
results of type T via get. Results are pushed
by the server at the rate selected by
set_rate. And consumers may block until a
stream’s value has changed with wait.
The stream will attempt to remove itself when dropped. Otherwise, the server will remove remaining streams when the client disconnects.
Implementations§
Source§impl<T: RpcType + Send> Stream<T>
impl<T: RpcType + Send> Stream<T>
Sourcepub fn set_rate(&self, hz: f32) -> Result<(), RpcError>
pub fn set_rate(&self, hz: f32) -> Result<(), RpcError>
Set the update rate for this streaming procedure.
Examples found in repository?
7fn main() -> Result<(), Box<dyn Error>> {
8 let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10 let space_center = SpaceCenter::new(client.clone());
11
12 // Set up a stream.
13 let ut_stream = space_center.get_ut_stream()?;
14 ut_stream.set_rate(1f32)?;
15
16 // Wait for updates, and print the current value.
17 for _ in 0..10 {
18 ut_stream.wait();
19 println!("It's {} o'clock", ut_stream.get()?);
20 }
21
22 Ok(())
23}Sourcepub fn get(&self) -> Result<T, RpcError>
pub fn get(&self) -> Result<T, RpcError>
Retrieve the current result received for this
procedure. This value is not guaranteed to have
changed since the last call to get. Use
wait to block until the value has changed.
Examples found in repository?
7fn main() -> Result<(), Box<dyn Error>> {
8 let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10 let space_center = SpaceCenter::new(client.clone());
11
12 // Set up a stream.
13 let ut_stream = space_center.get_ut_stream()?;
14 ut_stream.set_rate(1f32)?;
15
16 // Wait for updates, and print the current value.
17 for _ in 0..10 {
18 ut_stream.wait();
19 println!("It's {} o'clock", ut_stream.get()?);
20 }
21
22 Ok(())
23}Sourcepub fn wait(&self)
pub fn wait(&self)
Block the current thread of execution until this stream receives an update from the server.
Examples found in repository?
7fn main() -> Result<(), Box<dyn Error>> {
8 let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10 let space_center = SpaceCenter::new(client.clone());
11
12 // Set up a stream.
13 let ut_stream = space_center.get_ut_stream()?;
14 ut_stream.set_rate(1f32)?;
15
16 // Wait for updates, and print the current value.
17 for _ in 0..10 {
18 ut_stream.wait();
19 println!("It's {} o'clock", ut_stream.get()?);
20 }
21
22 Ok(())
23}Sourcepub fn wait_timeout(&self, dur: Duration)
pub fn wait_timeout(&self, dur: Duration)
Block the current thread of execution until this stream receives an update from the server or the timeout is reached.