Waited   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 34
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A perform() 0 3 1
A add() 0 3 1
A done() 0 3 1
1
<?php
2
/**
3
 * Bootstrap waited
4
 * User: moyo
5
 * Date: 11/10/2017
6
 * Time: 5:03 PM
7
 */
8
9
namespace Carno\Console\Boot;
10
11
use function Carno\Coroutine\all;
12
use Carno\Promise\Promise;
13
use Carno\Promise\Promised;
14
15
class Waited
16
{
17
    /**
18
     * @var mixed[]
19
     */
20
    private $chain = [];
21
22
    /**
23
     * @var Promised
24
     */
25
    private $done = null;
26
27
    /**
28
     * @param mixed[] $programs
29
     */
30
    public function add(...$programs) : void
31
    {
32
        $this->chain = array_merge($this->chain, $programs);
33
    }
34
35
    /**
36
     * @return Promised
37
     */
38
    public function done() : Promised
39
    {
40
        return $this->done ?? $this->done = Promise::deferred();
41
    }
42
43
    /**
44
     * @return Promised
45
     */
46
    public function perform() : Promised
47
    {
48
        return all(...$this->chain)->sync($this->done());
49
    }
50
}
51