| Total Complexity | 13 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | trait CWorker |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var Connections |
||
| 18 | */ |
||
| 19 | private $connections = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $timer = null; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var int |
||
| 28 | */ |
||
| 29 | private $ivs = 0; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var callable |
||
| 33 | */ |
||
| 34 | private $ex = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @return Connections |
||
| 38 | */ |
||
| 39 | protected function conn() : Connections |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param Connections $connections |
||
| 46 | */ |
||
| 47 | protected function track(Connections $connections) : void |
||
| 48 | { |
||
| 49 | $this->connections = $connections; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | */ |
||
| 54 | public function untrack() : void |
||
| 55 | { |
||
| 56 | $this->ex = null; |
||
| 57 | $this->connections = null; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param int $ivs |
||
| 62 | * @param callable $processor |
||
| 63 | */ |
||
| 64 | protected function ticker(int $ivs, callable $processor) : void |
||
| 65 | { |
||
| 66 | $ivs > 0 && $this->timer = Timer::loop(($this->ivs = $ivs) * 1000, $this->ex = $processor); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | */ |
||
| 71 | public function pause() : void |
||
| 72 | { |
||
| 73 | $this->timer && Timer::clear($this->timer) && $this->timer = null; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | */ |
||
| 78 | public function resume() : void |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | */ |
||
| 85 | public function shutdown() : void |
||
| 89 | } |
||
| 90 | } |
||
| 91 |