gobstore/watchflush.go
2025-01-12 02:51:51 -07:00

28 lines
577 B
Go

package gobstore
import (
"fmt"
"time"
)
// WatchFlush checks every 5 minutes to save file to disk.
func (j *GobStore[T]) WatchFlush() {
fmt.Println("Watching to flush " + j.path + "...")
defer j.Unlock() // try this if it panics...
ticker := time.NewTicker(time.Minute * 5)
defer ticker.Stop()
for range ticker.C {
j.Lock()
t := timer("flushwatch")
if j.dirty {
fmt.Println("dirty, saving: " + j.path)
j.Hidden_save()
} else {
fmt.Println("clean, skipping: " + j.path)
}
t()
j.Unlock() // force unlock in loop
}
fmt.Println("finished...")
}