[−][src]Function fleetspeak::collect
pub fn collect<M>(rate: Duration) -> Result<Packet<M>, ReadError> where
M: Message + Default + 'static,
Collects a message from the Fleetspeak server.
Unlike receive
, collect
will send heartbeat signals at the specified
rate
while waiting for the message.
This function is useful in the main loop of your service when it is not
supposed to do anything until a request from the server arrives. If your
service is actually awaiting for a specific message to come, you should
use receive
instead.
In case of any I/O failure or malformed message (e.g. due to parsing issues or when some fields are not being present), an error is reported.
Examples
use std::time::Duration; match fleetspeak::collect::<String>(Duration::from_secs(1)) { Ok(packet) => println!("Hello, {}!", packet.data), Err(error) => eprintln!("failed to collected the packet: {}", error), }