Is it possible to implement a custom hardware-timer-based scheduler for reactive extensions? How would I even start, are there any good examples?
I have a hardware that can send me an accurate interrupt each millisecond. I would like to leverage it to create a more precise RX scheduler.
UPDATE
Thanks to the keywords from Asti’s answer I found this blog post, which lead me to the discovery that I can implement a VirtualTimeScheduler<TAbsolute, TRelative>, since my hardware device provides me with absolute timestamps.
I’m not sure how accurately it would pan-out (deadline guarantees are difficult to make in GC’d systems), but here’s how I might start off.
Start off with by implementing the
ISchedulerinterface.Internally, use the
System.Reactive.Concurrency.SchedulerQueue<TAbsolute>class to maintain a prioritised queue of scheduled items.TAbsoluteis the type of the absolute due time of each scheduled item, so it might be easier if you choose a numeric type closest to the one provided by your hardware.By using a prioritised queue for items, you only have evaluate the whether the first item in the queue is due. You can probably cache the next due time and compare it on every interrupt.
Additionally, implement the
ISchedulerPeriodicinterface, which allows it to be more optimized towards recurring schedules.Good luck!