Test Failed
Push — master ( 08b170...e6bc2a )
by Kirill
02:02
created

Process::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler;
11
12
/**
13
 * Class Process
14
 */
15
class Process
16
{
17
    /**
18
     * @var \SplQueue|\Closure[]
19
     */
20
    private $deferred;
21
22
    /**
23
     * Process constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->deferred = new \SplQueue();
28
    }
29
30
    /**
31
     * @param \Closure $deferred
32
     */
33
    public function async(\Closure $deferred): void
34
    {
35
        $this->deferred[] = $deferred;
36
    }
37
38
    /**
39
     * @param array $args
40
     * @return void
41
     */
42
    public function run(...$args): void
43
    {
44
        while ($this->deferred->count()) {
45
            $callback = $this->deferred->pop();
46
            $callback(...$args);
47
        }
48
    }
49
}
50