Skip to content

Commit

Permalink
Cancel previous async login when starting new one
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Mar 28, 2024
1 parent 7ea8c6d commit 074ad64
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion user.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str
errChanPtr := &errChan
if !user.googleAsyncPairErrChan.CompareAndSwap(nil, errChanPtr) {
close(errChan)
outErr = ErrLoginInProgress
outErr = fmt.Errorf("%w: wait not called", ErrLoginInProgress)
return
}
var callbackDone bool
Expand All @@ -480,6 +480,10 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str
outEmoji = emoji
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
ctx, user.cancelLogin = context.WithCancel(context.Background())
go func() {
Expand Down

0 comments on commit 074ad64

Please sign in to comment.