Cancel previous async login when starting new one
This commit is contained in:
parent
7ea8c6d10d
commit
074ad64773
1 changed files with 5 additions and 1 deletions
6
user.go
6
user.go
|
@ -468,7 +468,7 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str
|
||||||
errChanPtr := &errChan
|
errChanPtr := &errChan
|
||||||
if !user.googleAsyncPairErrChan.CompareAndSwap(nil, errChanPtr) {
|
if !user.googleAsyncPairErrChan.CompareAndSwap(nil, errChanPtr) {
|
||||||
close(errChan)
|
close(errChan)
|
||||||
outErr = ErrLoginInProgress
|
outErr = fmt.Errorf("%w: wait not called", ErrLoginInProgress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var callbackDone bool
|
var callbackDone bool
|
||||||
|
@ -480,6 +480,10 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str
|
||||||
outEmoji = emoji
|
outEmoji = emoji
|
||||||
initialWait.Done()
|
initialWait.Done()
|
||||||
}
|
}
|
||||||
|
if cancelPrevLogin := user.cancelLogin; cancelPrevLogin != nil {
|
||||||
|
user.zlog.Warn().Msg("Another async google login started while previous one was in progress")
|
||||||
|
cancelPrevLogin()
|
||||||
|
}
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
ctx, user.cancelLogin = context.WithCancel(context.Background())
|
ctx, user.cancelLogin = context.WithCancel(context.Background())
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in a new issue