Skip to main content

service_status_loop

Macro service_status_loop 

Source
macro_rules! service_status_loop {
    ($interval:expr, $body:block) => { ... };
}
Expand description

Spawns a tokio task that executes $body then sleeps $interval, forever.

All variables referenced in $body are captured by move into the spawned task — they must be Send + 'static. Returns a tokio::task::JoinHandle<()>.

§Example

ⓘ
let mut writer = svc.create_writer::<SystemStatus_>("SystemStatus", TopicQos::default())?;
let mut msg = svc.create_message::<SystemStatus_>()?;
service_status_loop!(Duration::from_secs(1), {
    rcal::update_message_header!(msg);
    if let Err(e) = writer.write(&msg) {
        slog::error!(logger, "write failed"; "error" => %e);
    }
});
// `writer` and `msg` are now owned by the spawned task.