ReaderLoopProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Inspector\Daemon\Reader\Worker;
15
16
use PhpProfiler\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;
17
use PhpProfiler\Lib\Loop\AsyncLoop;
18
use PhpProfiler\Lib\Loop\AsyncLoopBuilder;
19
use PhpProfiler\Lib\Loop\AsyncLoopMiddleware\CallableMiddlewareAsync;
20
use PhpProfiler\Lib\Loop\AsyncLoopMiddleware\NanoSleepMiddlewareAsync;
21
use PhpProfiler\Lib\Loop\AsyncLoopMiddleware\RetryOnExceptionMiddlewareAsync;
22
use PhpProfiler\Lib\Process\MemoryReader\MemoryReaderException;
23
24
final class ReaderLoopProvider
25
{
26
    public function __construct(
27
        private AsyncLoopBuilder $loop_builder
28
    ) {
29
    }
30
31
    public function getMainLoop(callable $main, TraceLoopSettings $settings): AsyncLoop
32
    {
33
        return $this->loop_builder
34
            ->addProcess(
35
                RetryOnExceptionMiddlewareAsync::class,
36
                [
37
                    $settings->max_retries,
38
                    [MemoryReaderException::class]
39
                ]
40
            )
41
            ->addProcess(NanoSleepMiddlewareAsync::class, [$settings->sleep_nano_seconds])
42
            ->addProcess(CallableMiddlewareAsync::class, [$main])
43
            ->build();
44
    }
45
}
46