Bathtor / rust-hash-wheel-timer

A simple hash wheel timer supporting both periodic and one-off events

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] how to tick many ms for a timer?

nneesshh opened this issue · comments

Method tick() just advance 1ms, should I use "for i in 1..1000" to tick 1 second? Could I tick many ms with one method only?

Yeah, you kind of gotta tick individually. There is support for skipping through empty regions, but I'm not sure if that's what you are looking for.
From a data-structure perspective, you'll anyway have to look into all the slots when you tick 1 second at once, so I'm uncertain if it would make a performance difference to have this as a special method.

Many thanks for your answer. What I want is input an elapsed duration and trigger all expired callbacks, it is common for my "update( elapsed )" method. I just wonder is there a simple way to collect all expired callbacks. Thanks again for your elegant code project.

Yeah, that's what I thought. We don't have this atm.
My suggestion would be that you use the for....tick() method for now, maybe wrap it in a nice trait, if you want the convenience in your project.
And if you see any performance issues with that, come back and file another ticket with the benchmark that shows the issue and then we can look if we can maybe make this better with a more specialised API.
For now, I'll close this, since I understand your question was answered.