Completed
Push — master ( 496e6f...9f6541 )
by Shinji
21s queued 11s
created

ReaderLoopProvider::getMainLoop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 13
rs 10
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
    private AsyncLoopBuilder $loop_builder;
27
28
    public function __construct(AsyncLoopBuilder $loop_builder)
29
    {
30
        $this->loop_builder = $loop_builder;
31
    }
32
33
    public function getMainLoop(callable $main, TraceLoopSettings $settings): AsyncLoop
34
    {
35
        return $this->loop_builder
36
            ->addProcess(
37
                RetryOnExceptionMiddlewareAsync::class,
38
                [
39
                    $settings->max_retries,
40
                    [MemoryReaderException::class]
41
                ]
42
            )
43
            ->addProcess(NanoSleepMiddlewareAsync::class, [$settings->sleep_nano_seconds])
44
            ->addProcess(CallableMiddlewareAsync::class, [$main])
45
            ->build();
46
    }
47
}
48