zephyr::sync::channel

Function event_loop_useless

Source
pub async fn event_loop_useless<T, EF, EFF>(
    events: Receiver<T>,
    period: Duration,
    handle: EF,
) -> !
where EF: FnMut(Option<T>) -> EFF, EFF: Future<Output = ()>,
Expand description

Wait loop

A common scenario for async work tasks is to wait for, and process messages off of a queue, but to also wake periodically to perform some task.

This performs this periodic loop. It has some support for handling the case where the processing takes longer than the loop duration, but it merely re-schedules for the period past the current time. This means the phase of the period will change upon dropped ticks.

Each time an event is received, ‘handle’ is called with Some(ev). In addition, periodically (based on period) handle will be called with None.

Note: It needs to be a single handler, because this closure will frequently be in a move closure, and this would force shared data to be shared in Sync types of wrappers. The main purpose of combining the event handling and the periodic is to avoid that.

Note that also, if the timer is just barely able to run, it will still be scheduled “shortly” in the future.

T is the type of the messages expected to be received.

TODO: This function, in general, is completely worthless without Rust support for async closures.