Skip to content

Discussion: Add way to read the current timer value in CountDown trait #186

Open
@conorpp

Description

@conorpp

I'd like to use a timer to measure how long something takes. I can't use the timer trait currently since there's no way to read the current timer value. What do we think about adding a method to CountDown that returns the current timer value?

For example, see lap method below.

pub trait CountDown {
    /// The unit of time used by this timer
    type Time;

    /// Starts a new count down
    fn start<T>(&mut self, count: T)
    where
        T: Into<Self::Time>;

    /// Returns the current value of the timer as how much time has elapsed since starting.
    fn lap<T>(&self,) -> T
    where
        T: Into<Self::Time>;

    /// Non-blockingly "waits" until the count down finishes
    ///
    /// # Contract
    ///
    /// - If `Self: Periodic`, the timer will start a new count down right after the last one
    /// finishes.
    /// - Otherwise the behavior of calling `wait` after the last call returned `Ok` is UNSPECIFIED.
    /// Implementers are suggested to panic on this scenario to signal a programmer error.
    fn wait(&mut self) -> nb::Result<(), Infallible>;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions