Skip to content

Behavior of Timeout class is not entirely intuitive #98

@dallmair

Description

@dallmair

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:

  1. 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.
  2. Add a method stoppedOrExpired(), which at least shows up in IntelliSense and should make developers think.
  3. Add another class Delay that actually implements delay semantics. Could use Timeout internally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions