ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.04k stars 371 forks source link

feature request: callback on timer functions to handle changes in the time list #871

Open KammutierSpule opened 3 months ago

KammutierSpule commented 3 months ago

would be possible to register a callback on timer functions, so I can be notified when there is a change (insert/remove) on the list?

reason: this way I can wake-up a semaphore, so it will request the time to sleep until next timer... (instead of implement a "fixed polling rate").

jwellbelove commented 2 months ago

Which particular timer type are you working with? I can send you a possible implementation for you to test.

KammutierSpule commented 2 months ago

I don't mind to do a code review before testing, do you have it on a branch?

jwellbelove commented 2 months ago

I've done a quick change to etl::callback_timer on feature/#871-callback-on-timer-functions-to-handle-changes-in-the-time-list

I added member functions:-

void set_event_callbacks(event_callback_type insert, event_callback_type remove)
void clear_event_callbacks()

Where event_callback_type is etl::delegate<void(etl::timer::id::type)>

I haven't written any unit tests for it yet.

jwellbelove commented 2 months ago

If you want to set just one event callback then set the other to etl::callback_timer::event_callback{}