ETLCPP / etl

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

Add has_active_timer to callback_timer #847

Closed itavero closed 2 months ago

itavero commented 4 months ago

We are using time_to_next in our code to know when we should call tick again if no other events in our system have taken place. However, you need to know if any timers are active before calling this method.

I'd suggest to add a method that expose the has_active_timer check (e.g. !active_list.empty()), which is also done in the current tick implementation. Alternatively/additionally, perhaps time_to_next should return 0 if there is no active timer (as a delta value of 0 would never be in the list, so it's a safe "special" value to use for this case).

Just for reference: time_to_next was introduced in 11daaa398b930189d8f6db4c9d652eb834026913 (because of #744)

itavero commented 3 months ago

@jwellbelove Any particular reason you made etl::timer::interval::No_Active_Interval equal to 0xFFFFFFFFUL instead of 0?

jwellbelove commented 3 months ago

'Impossible' interval number

itavero commented 2 months ago

Sorry for the late reply. My point was more that 0 is also a "real" impossible value for interval (as the timer would have already been served in that case).

jwellbelove commented 2 months ago

It shouldn't really matter what the value of etl::timer::interval::No_Active_Interval is, as any code that checks for this should be comparing against the constant name, and not a literal value.

itavero commented 2 months ago

That's true. However, after analyzing the latest released code, I noticed with that version just checking if the result of time_to_next is 0 already tells you that there's no active timers. By using the same value in this update, the result remains the "same".

But indeed, other than that, I don't really care about the exact value either.

jwellbelove commented 2 months ago

That's a fair point.

jwellbelove commented 2 months ago

Fixed 20.38.11