You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
696 B
Go

package main
import (
"fmt"
"io"
"os"
"time"
)
const finalWord = "Go!"
// const countDownStart = 3
type Sleeper interface {
Sleep()
}
// type DefaultSleeper struct{}
// func (d *DefaultSleeper) Sleep() {
// time.Sleep(1 * time.Second)
// }
type ConfigurableSleeper struct {
duration time.Duration
sleep func(time.Duration)
}
func (c *ConfigurableSleeper) Sleep() {
c.sleep(c.duration)
}
func Countdown(out io.Writer, sleeper Sleeper, count int) {
for i := count; i > 0; i-- {
fmt.Fprint(out, i, "\n")
sleeper.Sleep()
}
fmt.Fprint(out, finalWord, "\n")
}
func main() {
sleeper := &ConfigurableSleeper{1 * time.Second, time.Sleep}
Countdown(os.Stdout, sleeper, 3)
}