Add the ability to compare a timer to another value.#13
Conversation
This allows checking whether the last measured time is greater or less than some 'reference' value. This is useful if you want to display messages if some operation has taken too long in the past.
|
I should note that I already use a pattern like this in a GUI application I have; |
|
@janfreyberg Thanks for the PR. This is an interesting use case. A couple of suggestions:
Thanks for the idea. |
|
Hmm ... reusing the |
|
Sounds good!
I didn't know about this dataclass feature. I initially tried to save some code by using the |
|
Hi, I had a look at how the comparison operators are implemented in data classes, and I don't think my suggestion will work, because they will only compare to other In the spirit of keeping this as simple as possible, I suggest the following:
What do you think? |
|
Sounds like a good plan to me; all very good points :) I'll do that now. |
- also removes comparators, as timer.last can be used for comparison
|
Brilliant, thank you so much! I'll add the changelog and list of contributors later today, and then make a new release on PyPI. |
|
Awesome, thank you 😃 will update my GUI projects as soon as the new release is out. |
|
|
This allows checking whether the last measured time is greater
or less than some 'reference' value.
Timerclass now has a reference to the last-measured value; initially this isnanTimerobjects.This is useful if you want to display messages if some operation
has taken too long in the past.
For example:
This results in a message being displayed when the function is used for the
second time: