Lines
100.00%
8 / 8
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| resolve | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| fail | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| expire | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| awaitOutcome | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 16 | final readonly class DeferredWait implements PendingWait | |
| 17 | { | |
| 18 | /** @var DeferredFuture<T|null> */ | |
| 19 | private DeferredFuture $outcome; | |
| 20 | ||
| 21 | public function __construct() | |
| 22 | { | |
| 23 | $this->outcome = new DeferredFuture(); | |
| 24 | } | |
| 25 | ||
| 26 | public function resolve(mixed $value): void | |
| 27 | { | |
| 28 | if (!$this->outcome->isComplete()) { | |
| 29 | $this->outcome->complete($value); | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | public function fail(Throwable $reason): void | |
| 34 | { | |
| 35 | if (!$this->outcome->isComplete()) { | |
| 36 | $this->outcome->error($reason); | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | public function expire(): void | |
| 41 | { | |
| 42 | if (!$this->outcome->isComplete()) { | |
| 43 | $this->outcome->complete(null); | |
| 44 | } | |
| 45 | } | |
| 46 | ||
| 47 | /** @return T|null */ | |
| 48 | public function awaitOutcome(): mixed | |
| 49 | { | |
| 50 | return $this->outcome->getFuture()->await(); | |
| 51 | } | |
| 52 | } |