Skip to main content

cobs_io_async/
timer.rs

1use core::task::{Context, Poll};
2
3/// A monotonic clock and wakeup source for retransmission deadlines.
4///
5/// Reading a timestamp alone is not enough: a lost packet must cause the
6/// connection to be polled again when its deadline arrives, so a timer also
7/// registers wakeups. Implement this for your platform's clock and timer
8/// facility.
9///
10/// All values are `u64` ticks of a unit you choose, for example
11/// milliseconds. [`Config::retransmit_timeout`](crate::Config::retransmit_timeout)
12/// uses the same unit.
13pub trait Timer {
14    /// Returns the current time in ticks.
15    ///
16    /// Must be monotonic: successive calls never return a smaller value.
17    fn now(&self) -> u64;
18
19    /// Returns `Ready` once [`now`](Self::now) has reached `deadline`.
20    ///
21    /// Otherwise returns `Pending` after arranging for `cx.waker()` to be
22    /// woken no later than the deadline. Deadlines are computed with
23    /// saturating addition, so `u64::MAX` means "never".
24    fn poll_deadline(&mut self, cx: &mut Context<'_>, deadline: u64) -> Poll<()>;
25}