client: Wait before returning from disconnect

This commit is contained in:
Toni Spets
2025-04-09 10:49:45 +03:00
parent 10b8c4b635
commit 538f2a2ec0
3 changed files with 21 additions and 7 deletions
+5 -1
View File
@@ -44,6 +44,7 @@ type PhoneLogin struct {
authClient *telegram.Client
authClientCtx context.Context
authClientCancel context.CancelFunc
authClientCloseC <-chan struct{}
phone string
hash string
@@ -55,6 +56,9 @@ func (p *PhoneLogin) Cancel() {
if p.authClientCancel != nil {
p.authClientCancel()
}
if p.authClientCloseC != nil {
<-p.authClientCloseC
}
}
func (p *PhoneLogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
@@ -85,7 +89,7 @@ func (p *PhoneLogin) SubmitUserInput(ctx context.Context, input map[string]strin
})
var err error
p.authClientCtx, p.authClientCancel = context.WithTimeoutCause(log.WithContext(context.Background()), time.Hour, errors.New("phone login took over one hour"))
if err = connectTelegramClient(p.authClientCtx, p.authClientCancel, p.authClient); err != nil {
if p.authClientCloseC, err = connectTelegramClient(p.authClientCtx, p.authClientCancel, p.authClient); err != nil {
return nil, err
}
sentCode, err := p.authClient.Auth().SendCode(p.authClientCtx, p.phone, auth.SendCodeOptions{})