amp
amp copied to clipboard
Add Interval
This adds a utility class Interval
which controls a repeating timer, automatically cancelling the timer when the object is destroyed.
The main use-case of this object is to store an instance of Interval
as an object property. When the holding object is destroyed, the repeating timer will be cancelled. This avoids a bit of boilerplate in the class, such as needing to declare a destructor to manually cancel the event loop callback.
The value here isn't necessarily huge, but this is a pattern we frequently use for classes with self-cleanup mechanisms such as LocalCache
.