Lines
100.00%
9 / 9
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RevoltTimerHandle | 100.00% | 9 / 9 | 100.00% | 4 / 4 | 5 | 100.00% | 1 / 1 | |||
| attachWatcher | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| markFired | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| cancel | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | |||||
| isPending | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Support\Time; | |
| 6 | ||
| 7 | use Revolt\EventLoop; | |
| 8 | use Stewart\Contracts\Time\TimerHandle; | |
| 9 | ||
| 10 | /** @internal */ | |
| 11 | final class RevoltTimerHandle implements TimerHandle | |
| 12 | { | |
| 13 | private ?string $identifier = null; | |
| 14 | ||
| 15 | private bool $pending = true; | |
| 16 | ||
| 17 | public function attachWatcher(string $identifier): void | |
| 18 | { | |
| 19 | $this->identifier = $identifier; | |
| 20 | } | |
| 21 | ||
| 22 | public function markFired(): void | |
| 23 | { | |
| 24 | $this->pending = false; | |
| 25 | $this->identifier = null; | |
| 26 | } | |
| 27 | ||
| 28 | public function cancel(): void | |
| 29 | { | |
| 30 | $this->pending = false; | |
| 31 | ||
| 32 | if ($this->identifier === null) { | |
| 33 | return; | |
| 34 | } | |
| 35 | ||
| 36 | EventLoop::cancel($this->identifier); | |
| 37 | $this->identifier = null; | |
| 38 | } | |
| 39 | ||
| 40 | public function isPending(): bool | |
| 41 | { | |
| 42 | return $this->pending; | |
| 43 | } | |
| 44 | } |