Update delete loop

This commit is contained in:
mcrakhman 2023-01-17 00:04:14 +01:00
parent ea5856c4b0
commit fb4e2b1fc9
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B

View File

@ -2,8 +2,11 @@ package settings
import (
"context"
"time"
)
const deleteLoopInterval = time.Second * 20
type deleteLoop struct {
deleteCtx context.Context
deleteCancel context.CancelFunc
@ -30,12 +33,17 @@ func (dl *deleteLoop) Run() {
func (dl *deleteLoop) loop() {
defer close(dl.loopDone)
dl.deleteFunc()
ticker := time.NewTicker(deleteLoopInterval)
defer ticker.Stop()
for {
select {
case <-dl.deleteCtx.Done():
return
case <-dl.deleteChan:
dl.deleteFunc()
ticker.Reset(deleteLoopInterval)
case <-ticker.C:
dl.deleteFunc()
}
}
}