Heartbeat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A keeping() 0 10 2
1
<?php
2
/**
3
 * Heartbeats manager
4
 * User: moyo
5
 * Date: 09/08/2017
6
 * Time: 5:47 PM
7
 */
8
9
namespace Carno\Pool\Features;
10
11
use Carno\Pool\Chips\CWorker;
12
use Carno\Pool\Connections;
13
use Carno\Pool\Options;
14
use Carno\Pool\Poolable;
15
16
class Heartbeat
17
{
18
    use CWorker;
19
20
    /**
21
     * Heartbeat constructor.
22
     * @param Options $options
23
     * @param Connections $connections
24
     */
25
    public function __construct(Options $options, Connections $connections)
26
    {
27
        $this->track($connections);
28
        $this->ticker($options->hbInterval, [$this, 'keeping']);
29
    }
30
31
    /**
32
     */
33
    public function keeping() : void
34
    {
35
        /**
36
         * @var Poolable $conn
37
         */
38
        while (null !== $conn = $this->conn()->getIdled(false, false)) {
39
            $conn->heartbeat()->then(static function () use ($conn) {
40
                $conn->release();
41
            }, static function () use ($conn) {
42
                $conn->destroy();
43
            });
44
        }
45
    }
46
}
47