mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-11-26 20:04:45 +01:00
Add mutex
This commit is contained in:
parent
40d16c372a
commit
083c933ad3
@ -48,12 +48,12 @@ class Client
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalKeyedMutex $mutex;
|
private static LocalKeyedMutex $mutex;
|
||||||
|
|
||||||
public function addSession(string $session, array $settings = []): API
|
public function addSession(string $session, array $settings = []): API
|
||||||
{
|
{
|
||||||
$this->mutex ??= new LocalKeyedMutex;
|
self::$mutex ??= new LocalKeyedMutex;
|
||||||
$lock = $this->mutex->acquire($session);
|
$lock = self::$mutex->acquire($session);
|
||||||
if (isset($this->instances[$session])) {
|
if (isset($this->instances[$session])) {
|
||||||
throw new InvalidArgumentException('Session already exists');
|
throw new InvalidArgumentException('Session already exists');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user