Lines
50.00%
3 / 6
Functions and Methods
50.00%
3 / 6
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ManualTimeout | 50.00% | 3 / 6 | 50.00% | 3 / 6 | 10.50 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| __destruct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| subscribe | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| unsubscribe | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| isRequested | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| throwIfRequested | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Testing\Time; | |
| 6 | ||
| 7 | use Amp\Cancellation; | |
| 8 | use Closure; | |
| 9 | use Stewart\Contracts\Time\TimerHandle; | |
| 10 | ||
| 11 | final class ManualTimeout implements Cancellation | |
| 12 | { | |
| 13 | public function __construct( | |
| 14 | private readonly Cancellation $cancellation, | |
| 15 | private readonly TimerHandle $timer, | |
| 16 | ) {} | |
| 17 | ||
| 18 | // Mirrors TimeoutCancellation: an abandoned deadline must not stay pending. | |
| 19 | public function __destruct() | |
| 20 | { | |
| 21 | $this->timer->cancel(); | |
| 22 | } | |
| 23 | ||
| 24 | public function subscribe(Closure $callback): string | |
| 25 | { | |
| 26 | return $this->cancellation->subscribe($callback); | |
| 27 | } | |
| 28 | ||
| 29 | public function unsubscribe(string $id): void | |
| 30 | { | |
| 31 | $this->cancellation->unsubscribe($id); | |
| 32 | } | |
| 33 | ||
| 34 | public function isRequested(): bool | |
| 35 | { | |
| 36 | return $this->cancellation->isRequested(); | |
| 37 | } | |
| 38 | ||
| 39 | public function throwIfRequested(): void | |
| 40 | { | |
| 41 | $this->cancellation->throwIfRequested(); | |
| 42 | } | |
| 43 | } |