Skip to content

Commit

Permalink
feat(config): Add App config with TRAP_MAIN_LOOP_INTERVAL env
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Sep 25, 2024
1 parent 827614c commit 0a73206
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Buggregator\Trap;

use Buggregator\Trap\Config\Server\App;
use Buggregator\Trap\Config\Server\Files\SPX as SPXFileConfig;
use Buggregator\Trap\Config\Server\Files\XDebug as XDebugFileConfig;
use Buggregator\Trap\Config\Server\Files\XHProf as XHProfFileConfig;
Expand Down Expand Up @@ -113,8 +114,11 @@ public function __construct(
/**
* @param positive-int $sleep Sleep time in microseconds
*/
public function run(int $sleep = 50): void
public function run(): void
{
/** @var App $config */
$config = $this->container->get(App::class);
$sleep = \max(50, $config->mainLoopInterval);
foreach ($this->senders as $sender) {
\assert($sender instanceof Sender);
if ($sender instanceof Processable) {
Expand Down
23 changes: 23 additions & 0 deletions src/Config/Server/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Config\Server;

use Buggregator\Trap\Service\Config\Env;

/**
* Common configuration for the application
*
* @internal
* @psalm-internal Buggregator\Trap
*/
final class App
{
/**
* Main loop interval in microseconds
* @var int<50, max>
*/
#[Env('TRAP_MAIN_LOOP_INTERVAL')]
public int $mainLoopInterval = 100;
}

0 comments on commit 0a73206

Please sign in to comment.