KVStore   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A watching() 0 13 2
1
<?php
2
/**
3
 * KVStore reader
4
 * User: moyo
5
 * Date: 13/10/2017
6
 * Time: 5:45 PM
7
 */
8
9
namespace Carno\Consul;
10
11
use Carno\Channel\Chan;
12
use Carno\Consul\APIs\KVGetting;
13
use Carno\Consul\Chips\AgentRequired;
14
use Carno\Consul\Chips\GWatcher;
15
use Carno\Consul\Chips\WValues;
16
17
class KVStore
18
{
19
    use AgentRequired, WValues, GWatcher;
20
21
    /**
22
     * keys=* means all keys in folder
23
     * keys=abc means keys prefix with "abc"
24
     * @param string $folder
25
     * @param string $keys
26
     * @param Chan $notify
27
     */
28
    public function watching(string $folder, string $keys, Chan $notify) : void
29
    {
30
        $path = $keys === '*' ? $folder : sprintf('%s/%s', $folder, $keys);
31
32
        $ig = function () use ($path) {
33
            return (new KVGetting($this->agent))->path($path);
34
        };
35
36
        $do = function (KVGetting $lister) use ($notify) {
37
            yield $notify->send($this->changed(yield $lister->result()));
38
        };
39
40
        $this->nwProcess($notify->closed(), $ig, $do, 'KVStore watcher interrupted', ['path' => $path]);
41
    }
42
}
43