I would like a language-agnostic description of how to implement a timers library, where the library user can start timers (possibly many active at the same time), passing callbacks that should be run when the corresponding timer completes. It should allow to stop and start timers and check if they are still running.
The timer module will allow timers to have a time resolution of Ns and the module shall be given a kick every Ns to prompt the module to check for expired timers.
I'm specifically looking for a solution which
- is robust to timers being started / stopped while processing a timer expiry callback
- allows timers to be started, stopped and checked quickly
- has a small memory footprint