-
-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Interval #441
base: 3.x
Are you sure you want to change the base?
Add Interval #441
Conversation
src/Interval.php
Outdated
public function __destruct() | ||
{ | ||
EventLoop::cancel($this->watcher); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there also be a manual cancel
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense for the object to represent a valid repeating timer. If we allow external cancellation, then the object needs to expose an isCancelled()
method so the state isn't hidden.
It's just a |
How about moving this to |
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
.