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 | ||
| 9 | /** @internal */ | |
| 10 | final class RevoltTimerHandle implements TimerHandle | |
| 11 | { | |
| 12 | private ?string $identifier = null; | |
| 13 | ||
| 14 | private bool $pending = true; | |
| 15 | ||
| 16 | public function attachWatcher(string $identifier): void | |
| 17 | { | |
| 18 | $this->identifier = $identifier; | |
| 19 | } | |
| 20 | ||
| 21 | public function markFired(): void | |
| 22 | { | |
| 23 | $this->pending = false; | |
| 24 | $this->identifier = null; | |
| 25 | } | |
| 26 | ||
| 27 | public function cancel(): void | |
| 28 | { | |
| 29 | $this->pending = false; | |
| 30 | ||
| 31 | if ($this->identifier === null) { | |
| 32 | return; | |
| 33 | } | |
| 34 | ||
| 35 | EventLoop::cancel($this->identifier); | |
| 36 | $this->identifier = null; | |
| 37 | } | |
| 38 | ||
| 39 | public function isPending(): bool | |
| 40 | { | |
| 41 | return $this->pending; | |
| 42 | } | |
| 43 | } |