| Total Complexity | 6 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 18 | class Connections |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var Closeable[] |
||
| 22 | */ |
||
| 23 | private $connected = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param Address $address |
||
| 27 | * @param Closure $connector |
||
| 28 | * @return Outputter |
||
| 29 | */ |
||
| 30 | public function hosting(Address $address, Closure $connector) : Outputter |
||
| 35 | ; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $cid |
||
| 40 | * @param Closeable $conn |
||
| 41 | * @return Closeable|Outputter |
||
| 42 | */ |
||
| 43 | private function watch(string $cid, Closeable $conn) : Closeable |
||
| 44 | { |
||
| 45 | $conn->closed()->then(function () use ($cid) { |
||
| 46 | unset($this->connected[$cid]); |
||
| 47 | }); |
||
| 48 | |||
| 49 | return $conn; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param Address $address |
||
| 54 | * @return Promised |
||
| 55 | */ |
||
| 56 | public function close(Address $address) : Promised |
||
| 57 | { |
||
| 58 | return ($c = $this->connected[(string)$address] ?? null) ? $c->close() : Promise::resolved(); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return Promised |
||
| 63 | */ |
||
| 64 | public function release() : Promised |
||
| 73 | } |
||
| 74 | } |
||
| 75 |