mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-14 17:21:15 +00:00
47 lines
757 B
Go
47 lines
757 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func saveBackups(snapshotTicker, saveAfter <-chan time.Time) {
|
|
for {
|
|
select {
|
|
case <-snapshotTicker:
|
|
takeSnapshot()
|
|
case <-saveAfter:
|
|
saveSnapshot()
|
|
return
|
|
default:
|
|
waitForData()
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TEST SUITE - Don't touch below this line
|
|
|
|
func takeSnapshot() {
|
|
fmt.Println("Taking a backup snapshot...")
|
|
}
|
|
|
|
func saveSnapshot() {
|
|
fmt.Println("All backups saved!")
|
|
}
|
|
|
|
func waitForData() {
|
|
fmt.Println("Nothing to do, waiting...")
|
|
}
|
|
|
|
func test() {
|
|
snapshotTicker := time.Tick(800 * time.Millisecond)
|
|
saveAfter := time.After(2800 * time.Millisecond)
|
|
saveBackups(snapshotTicker, saveAfter)
|
|
fmt.Println("===========================")
|
|
}
|
|
|
|
func main() {
|
|
test()
|
|
}
|