Passed
Push — 0.6.x ( 9a1948...a98caa )
by Shinji
03:23 queued 01:32
created

ReaderLoopProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMainLoop() 0 13 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof 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 Reli\Inspector\Daemon\Reader\Worker;
15
16
use Reli\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;
17
use Reli\Lib\Loop\AsyncLoop;
18
use Reli\Lib\Loop\AsyncLoopBuilder;
19
use Reli\Lib\Loop\AsyncLoopMiddleware\CallableMiddlewareAsync;
20
use Reli\Lib\Loop\AsyncLoopMiddleware\NanoSleepMiddlewareAsync;
21
use Reli\Lib\Loop\AsyncLoopMiddleware\RetryOnExceptionMiddlewareAsync;
22
use Reli\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