Completed
Push — master ( 9f8be7...b45da4 )
by Vuong
02:22 queued 01:13
created

Pool::defaultOutputLength()   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 1
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/laravel-async
4
 *
5
 * @copyright (c) Vuong Xuong Minh
6
 * @license [MIT](https://opensource.org/licenses/MIT)
7
 */
8
9
namespace VXM\Async;
10
11
use Spatie\Async\Pool as BasePool;
12
use Spatie\Async\Process\Runnable;
13
use VXM\Async\Runtime\ParentRuntime;
14
15
/**
16
 * @author Vuong Minh <[email protected]>
17
 * @since 1.0.0
18
 */
19
class Pool extends BasePool
20
{
21
    /**
22
     * Default processes output length.
23
     *
24
     * @var int
25
     */
26
    protected $defaultOutputLength = 10240;
27
28
    /**
29
     * Flush the pool.
30
     */
31
    public function flush(): void
32
    {
33
        $this->inProgress = [];
34
        $this->timeouts = [];
35
        $this->finished = [];
36
        $this->queue = [];
37
        $this->failed = [];
38
        $this->results = [];
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function add($process, int $outputLength = null): Runnable
45
    {
46
        $outputLength = $outputLength ?? $this->defaultOutputLength;
47
48
        if (is_callable($process)) {
49
            $process = ParentRuntime::createProcess(
50
                $process,
51
                $outputLength,
52
                $this->binary
53
            );
54
        }
55
56
        return parent::add($process, $outputLength);
57
    }
58
59
    /**
60
     * Set default output length of child processes.
61
     *
62
     * @param  int  $defaultOutputLength
63
     * @since 2.1.0
64
     */
65
    public function defaultOutputLength(int $defaultOutputLength): void
66
    {
67
        $this->defaultOutputLength = $defaultOutputLength;
68
    }
69
}
70