Subscribe::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * NSQd subscribe
4
 * User: moyo
5
 * Date: 02/03/2018
6
 * Time: 11:47 AM
7
 */
8
9
namespace Carno\NSQ\Protocol;
10
11
use function Carno\Coroutine\go;
12
use Carno\NSQ\Connector\Nsqd;
13
use Carno\NSQ\Types\Consuming;
14
use Carno\Promise\Promised;
15
16
class Subscribe
17
{
18
    /**
19
     * Subscribe constructor.
20
     * @param Promised $connected
21
     * @param Nsqd $nsqd
22
     * @param Consuming $consuming
23
     */
24
    public function __construct(Promised $connected, Nsqd $nsqd, Consuming $consuming)
25
    {
26
        go(static function () use ($connected, $nsqd, $consuming) {
27
            if (yield $connected) {
28
                if (yield $nsqd->sub($consuming->topic(), $consuming->channel())) {
29
                    $nsqd->rdy($consuming->concurrency());
30
                }
31
            }
32
        });
33
    }
34
}
35