How implement a steady ticker (if feasible)?

⚓ Rust    📅 2025-10-19    👤 surdeus    👁️ 2      

surdeus

I'm developing a millisecond ticker to provide the timing for a polyrhythmic music sequencer. For this application, I think a steady sticker would be best. The priority is for the ticks to all occur after the same interval, as far as possible, rather than that, for example, after 600,000 1-millisecond ticks exactly 10 minutes elapsed time will has passed.

Rust has a SteadyClock. But I can't see how to get tick notifications out of it. Is there a way to get steady ticks that I have missed?

If not, my fallback option, which I have provisionally implemented, is Instant, of which there is a tokio version, which I'm using, and a std version. The documentation for Instant states that it is

A measurement of a monotonically nondecreasing clock. ... Instants are not guaranteed to be steady. In other words, each tick of the underlying clock might not be the same length (e.g. some seconds may be longer than others). An instant may jump forwards or experience time dilation (slow down or speed up), but it will never go backwards.

I don't understand how an instant could go backwards. Regardless of that, if it is not feasible to implement a steady ticker, Instant should be adequate. My tests show that it performs the same as JUCE's C++ class HighResolutionTimer, which is designed for music and I've used extensively.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed