feat: add checkEmailMutex the lock is to avoid duplicate check email, maybe multiple goroutine check email at the same time
This commit is contained in:
parent
611334b3e2
commit
5d1b64c3a4
1 changed files with 10 additions and 3 deletions
|
|
@ -49,9 +49,13 @@ const (
|
||||||
|
|
||||||
type EmailChannel struct {
|
type EmailChannel struct {
|
||||||
*channels.BaseChannel
|
*channels.BaseChannel
|
||||||
config config.EmailConfig
|
config config.EmailConfig
|
||||||
imapClient *client.Client
|
imapClient *client.Client
|
||||||
lastUID uint32
|
lastUID uint32
|
||||||
|
// checkEmailMutex
|
||||||
|
// maybe multiple goroutine check email at the same time, use mutex to avoid duplicate check
|
||||||
|
checkEmailMutex sync.Mutex
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
checkTicker *time.Ticker
|
checkTicker *time.Ticker
|
||||||
|
|
@ -580,6 +584,9 @@ func (c *EmailChannel) runIdleLoop(ctx context.Context, pollInterval time.Durati
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EmailChannel) CheckNewEmails(ctx context.Context) {
|
func (c *EmailChannel) CheckNewEmails(ctx context.Context) {
|
||||||
|
// the lock is to avoid duplicate check email, maybe multiple goroutine check email at the same time
|
||||||
|
c.checkEmailMutex.Lock()
|
||||||
|
defer c.checkEmailMutex.Unlock()
|
||||||
for {
|
for {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue