-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
The stopped() method returns the information whether the timeout is still running or not, and it does not check for expiration. The expired() method checks for expiration, and also stops the timer, so it only returns true a single time. In a table:
| Situation | stopped() | expired() |
|---|---|---|
| Stopped | true | false |
| Started, not expired yet | false | false |
| Started, expired | before expired() is called: false after expired() is called: true |
true, but only once false on second and all following calls |
The current implementation is good for use cases where some code needs to be run a single time after a timeout expires. However, it's not ideal for use cases where one actually needs "delay" semantics, i.e. do nothing while the timeout is running, but always run the code after expiration.
It's not clear at the moment what the best solution is. Ideas:
- Change semantics of the
expired()method to return true when the Timeout is stopped. Need to check all existing usages whether this is possible, and also whether it makes sense. - Add a method
stoppedOrExpired(), which at least shows up in IntelliSense and should make developers think. - Add another class
Delaythat actually implements delay semantics. Could useTimeoutinternally.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels