Open trowski opened 3 months ago
It's just a auto destruct
for EventLoop::repeat()??
I think it's not very necessary for a base library.
How about moving this to amphp/sync
? That library has sort of become a utility library.
I'd rather keep this here, as it's very basic, no?
@kelunik Yeah, I can't see this needing changing, so seems basic enough to go here. Should we add this then?
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
.