From 4ce65d59ca91871cfd126497158200a818720bce Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:30:08 +0200 Subject: Adding upstream version 0.13.1. Signed-off-by: Daniel Baumann --- vendor/ipl/scheduler/src/Common/Timers.php | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vendor/ipl/scheduler/src/Common/Timers.php (limited to 'vendor/ipl/scheduler/src/Common/Timers.php') diff --git a/vendor/ipl/scheduler/src/Common/Timers.php b/vendor/ipl/scheduler/src/Common/Timers.php new file mode 100644 index 0000000..2d0641f --- /dev/null +++ b/vendor/ipl/scheduler/src/Common/Timers.php @@ -0,0 +1,60 @@ + */ + protected $timers; + + /** + * Set a timer for the given UUID + * + * **Example Usage:** + * + * ```php + * $timers->attachTimer($uuid, Loop::addTimer($interval, $callback)); + * ``` + * + * @param UuidInterface $uuid + * @param TimerInterface $timer + * + * @return $this + */ + protected function attachTimer(UuidInterface $uuid, TimerInterface $timer): self + { + $this->timers->attach($uuid, $timer); + + return $this; + } + + /** + * Detach and return the timer for the given UUID, if any + * + * **Example Usage:** + * + * ```php + * Loop::cancelTimer($timers->detachTimer($uuid)); + * ``` + * + * @param UuidInterface $uuid + * + * @return ?TimerInterface + */ + protected function detachTimer(UuidInterface $uuid): ?TimerInterface + { + if (! $this->timers->contains($uuid)) { + return null; + } + + $timer = $this->timers->offsetGet($uuid); + + $this->timers->detach($uuid); + + return $timer; + } +} -- cgit v1.2.3