Waited::perform()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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