diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-01-23 10:30:02 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-01-23 10:30:02 +0300 |
commit | 18a17cb7a8abe0180bb4b1e8dd1f468956796922 (patch) | |
tree | 324dbaaf8b968b5b466ff5b9458eb777309d4dfb /telegram/connect.go | |
parent | d66f87485d2a96ad9723c537c3fd11ee27579104 (diff) |
Fix crash on login
Diffstat (limited to 'telegram/connect.go')
-rw-r--r-- | telegram/connect.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/telegram/connect.go b/telegram/connect.go index ed0a46b..0b9a195 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -96,11 +96,14 @@ func (stateHandler *clientAuthorizer) Close() { // Connect starts TDlib connection func (c *Client) Connect(resource string) error { + log.Warn("Attempting to connect to Telegram network...") + // avoid conflict if another authorization is pending already - c.locks.authorizationReady.Wait() + c.locks.authorizationReady.Lock() if c.Online() { c.roster(resource) + c.locks.authorizationReady.Unlock() return nil } @@ -116,15 +119,13 @@ func (c *Client) Connect(resource string) error { LastName: make(chan string, 1), } - c.locks.authorizationReady.Add(1) - go c.interactor() c.authorizer.TdlibParameters <- c.parameters tdlibClient, err := client.NewClient(c.authorizer, c.options...) if err != nil { - c.locks.authorizationReady.Done() + c.locks.authorizationReady.Unlock() return errors.Wrap(err, "Couldn't initialize a Telegram client instance") } @@ -142,7 +143,7 @@ func (c *Client) Connect(resource string) error { go c.updateHandler() c.online = true - c.locks.authorizationReady.Done() + c.locks.authorizationReady.Unlock() c.addResource(resource) go func() { |