Add mutex

This commit is contained in:
Daniil Gentili 2024-06-26 22:36:58 +02:00
parent ba8a8730a5
commit 561fec0a12

View File

@ -2,6 +2,7 @@
namespace TelegramApiServer; namespace TelegramApiServer;
use Amp\Sync\LocalKeyedMutex;
use danog\MadelineProto\API; use danog\MadelineProto\API;
use danog\MadelineProto\APIWrapper; use danog\MadelineProto\APIWrapper;
use danog\MadelineProto\Settings; use danog\MadelineProto\Settings;
@ -47,8 +48,11 @@ class Client
); );
} }
private LocalKeyedMutex $mutex;
public function addSession(string $session, array $settings = []): API public function addSession(string $session, array $settings = []): API
{ {
$lock = $this->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');
} }