carno-php /
nsq
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Normally nsqd daemon API |
||||||
| 4 | * User: moyo |
||||||
| 5 | * Date: 2018/7/6 |
||||||
| 6 | * Time: 12:03 PM |
||||||
| 7 | */ |
||||||
| 8 | |||||||
| 9 | namespace Carno\NSQ\Chips; |
||||||
| 10 | |||||||
| 11 | use function Carno\Coroutine\all; |
||||||
| 12 | use Carno\NSQ\Connector\Linker; |
||||||
| 13 | use Carno\Promise\Promise; |
||||||
| 14 | use Carno\Promise\Promised; |
||||||
| 15 | |||||||
| 16 | trait N2Daemon |
||||||
| 17 | { |
||||||
| 18 | /** |
||||||
| 19 | * @var Promised |
||||||
| 20 | */ |
||||||
| 21 | private $exited = null; |
||||||
| 22 | |||||||
| 23 | /** |
||||||
| 24 | * @see startup |
||||||
| 25 | * @deprecated |
||||||
| 26 | * @return Promised |
||||||
| 27 | */ |
||||||
| 28 | public function daemon() : Promised |
||||||
| 29 | { |
||||||
| 30 | return $this->startup(); |
||||||
| 31 | } |
||||||
| 32 | |||||||
| 33 | /** |
||||||
| 34 | * @return Promised |
||||||
| 35 | */ |
||||||
| 36 | private function exited() : Promised |
||||||
| 37 | { |
||||||
| 38 | return $this->exited ?? $this->exited = Promise::deferred(); |
||||||
| 39 | } |
||||||
| 40 | |||||||
| 41 | /** |
||||||
| 42 | * @return Promised |
||||||
| 43 | */ |
||||||
| 44 | public function startup() : Promised |
||||||
| 45 | { |
||||||
| 46 | return all($this->background(), $this->exited()); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 47 | } |
||||||
| 48 | |||||||
| 49 | /** |
||||||
| 50 | * @return Promised |
||||||
| 51 | */ |
||||||
| 52 | public function shutdown() : Promised |
||||||
| 53 | { |
||||||
| 54 | $waits = []; |
||||||
| 55 | |||||||
| 56 | $this->linkers(function (Linker $linker) use (&$waits) { |
||||||
|
0 ignored issues
–
show
It seems like
linkers() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 57 | array_push($waits, $linker->disconnect()); |
||||||
| 58 | }); |
||||||
| 59 | |||||||
| 60 | return all(...$waits)->sync($this->exited()); |
||||||
| 61 | } |
||||||
| 62 | } |
||||||
| 63 |