summaryrefslogtreecommitdiff
path: root/countdown.go
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-12-08 12:30:09 -0700
committermo khan <mo.khan@gmail.com>2019-12-08 12:30:09 -0700
commite67ebfe8bfca02403bffa9399043220e64323dca (patch)
treeef3767a94205fec75e794e2e074931307748b296 /countdown.go
parent233ade58dd180ac55e6ab68fbc69721a4cd75f11 (diff)
Add countdown
Diffstat (limited to 'countdown.go')
-rw-r--r--countdown.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/countdown.go b/countdown.go
new file mode 100644
index 0000000..1ba1999
--- /dev/null
+++ b/countdown.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "time"
+)
+
+type Sleeper interface {
+ Sleep()
+}
+
+type DefaultSleeper struct{}
+
+func (d *DefaultSleeper) Sleep() {
+ time.Sleep(1 * time.Second)
+}
+
+const finalWord = "Go!"
+const countdownStart = 3
+
+func Countdown(out io.Writer, sleeper Sleeper) {
+ for i := countdownStart; i > 0; i-- {
+ sleeper.Sleep()
+ fmt.Fprintln(out, i)
+ }
+
+ sleeper.Sleep()
+ fmt.Fprint(out, finalWord)
+}
+
+func main() {
+ sleeper := &DefaultSleeper{}
+ Countdown(os.Stdout, sleeper)
+}