Skip to content

Commit

Permalink
Add mutex for saving process
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Jun 18, 2023
1 parent 862587f commit 49f28e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"yiisoft/di": "^1.0",
"yiisoft/files": "^2.0",
"yiisoft/json": "^1.0",
"yiisoft/mutex": "^1.1",
"yiisoft/profiler": "^3.0",
"yiisoft/proxy": "^1.0.1",
"yiisoft/strings": "^2.0",
Expand Down
8 changes: 7 additions & 1 deletion src/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Debug;

use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Mutex\Synchronizer;
use Yiisoft\Strings\WildcardPattern;
use Yiisoft\Yii\Console\Event\ApplicationStartup;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
Expand All @@ -13,12 +14,15 @@

final class Debugger
{
public const SAVING_MUTEX_NAME = self::class;

private bool $skipCollect = false;
private bool $active = false;

public function __construct(
private DebuggerIdGenerator $idGenerator,
private StorageInterface $target,
private Synchronizer $synchronizer,
/**
* @var CollectorInterface[]
*/
Expand Down Expand Up @@ -64,7 +68,9 @@ public function shutdown(): void

try {
if (!$this->skipCollect) {
$this->target->flush();
$this->synchronizer->execute(self::SAVING_MUTEX_NAME . $this->idGenerator->getId(), function () {
$this->target->flush();
});
}
} finally {
foreach ($this->collectors as $collector) {
Expand Down

0 comments on commit 49f28e9

Please sign in to comment.