Update delete loop

This commit is contained in:
mcrakhman 2023-01-17 00:04:14 +01:00 committed by Mikhail Iudin
parent b0f684769a
commit bf76836a21
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0

View File

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