Add mutex

This commit is contained in:
Daniil Gentili 2024-06-26 22:39:31 +02:00
parent 40d16c372a
commit 083c933ad3

View File

@ -48,12 +48,12 @@ class Client
);
}
private LocalKeyedMutex $mutex;
private static LocalKeyedMutex $mutex;
public function addSession(string $session, array $settings = []): API
{
$this->mutex ??= new LocalKeyedMutex;
$lock = $this->mutex->acquire($session);
self::$mutex ??= new LocalKeyedMutex;
$lock = self::$mutex->acquire($session);
if (isset($this->instances[$session])) {
throw new InvalidArgumentException('Session already exists');
}