Update delete loop
This commit is contained in:
parent
b0f684769a
commit
bf76836a21
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user