1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Fixed-rate scheduling driven by the flight loop's `dt`, for streams (telemetry, heartbeats)
//! that run slower than the loop.
//!
//! A tick rarely divides a stream's period, so [`Every`] carries the leftover time into the
//! next period instead of discarding it: a 10 Hz stream on a 60 Hz loop sends 10 times per
//! second, not 60 / 7 ≈ 8.6. A gap longer than a period (a stalled tick) fires once and
//! drops the backlog rather than bursting.
use Duration;
/// Fires on the first call, then once per `interval` of accumulated `dt`.
///
/// # Examples
///
/// ```
/// use core::time::Duration;
/// use stable_flight::timing::Every;
///
/// // A 10 Hz stream on a 250 Hz loop.
/// let mut heartbeat = Every::new(Duration::from_millis(100));
/// let dt = Duration::from_millis(4);
/// let fired = (0..250).filter(|_| heartbeat.ready(dt)).count();
/// assert_eq!(fired, 11); // the first call, then 10 per second
/// ```