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...") }