commit 5893b1fa3dcd5803efe8ae71832b9aaec64c85e8 Author: Zorchenhimer Date: Sun Feb 28 00:35:02 2021 -0500 Initial commit "Works", but needs LOTS of polish. And some over engineering. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3876d7f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +countdown.txt diff --git a/main.go b/main.go new file mode 100644 index 0000000..5ffe3f4 --- /dev/null +++ b/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "os" + "time" + "sync" +) + +const filename string = "countdown.txt" +var until time.Time = time.Now().Add(time.Minute) + +func main() { + d, err := time.ParseDuration("1s") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + fmt.Printf("until: %s\n", until) + + wg := sync.WaitGroup{} + wg.Add(1) + ticker := time.NewTicker(d) + go func(c <-chan time.Time) { + fmt.Println("XX") + _ = <-c + count := time.Until(until) + for ; count >= 0; count = time.Until(until) { + _ = <-c + str := fmt.Sprintf("%02.0f:%02.0f:%02.0f\n", count.Hours(), count.Minutes(), count.Seconds()) + err = os.WriteFile(filename, []byte(str), 0777) + if err != nil { + fmt.Println("unable to write file: %v\n", err) + } + } + wg.Done() + }(ticker.C) + + wg.Wait() + + err = os.WriteFile(filename, []byte("00:00:00"), 0777) + if err != nil { + fmt.Println("unable to write file: %v\n", err) + } + + fmt.Println("\nDONE") +}