Lines 100.00% 7 / 7
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 startTimer 100.00% 5 / 5 100.00% 1 / 1 2
 waitFor 100.00% 1 / 1 100.00% 1 / 1 1
14final readonly class WorkerTimers implements Timers
15{
16    // Waits time out on the loop timers, so a paused app's wait still ends.
17    public function __construct(
18        private Scheduler $scheduler,
19        private Timers $loopTimers,
20    ) {}
21
22    public function startTimer(Duration $delay, Closure $callback): TimerHandle
23    {
24        $shortestDelay = Duration::milliseconds(1);
25        $task = $this->scheduler->runAfter($shortestDelay->isLongerThan($delay) ? $shortestDelay : $delay, static function () use ($callback): void {
26            $callback();
27        });
28
29        return new ScheduledTimerHandle($task);
30    }
31
32    /**
33     * @template T
34     * @param Closure(PendingWait<T>): (Closure(): void) $arm
35     * @return T|null
36     */
37    public function waitFor(Closure $arm, ?Duration $timeout = null): mixed
38    {
39        return $this->loopTimers->waitFor($arm, $timeout);
40    }
41}