package main

import (
	"fmt"
	"time"
)

func main() {
	// section: main
	ticker := time.NewTicker(time.Second)

	// always defer the `Stop` to ensure you don't leak a go routine
	defer ticker.Stop()

	done := make(chan bool)
	go func() {
		time.Sleep(10 * time.Second)
		// shut down the ticker
		ticker.Stop()
		done <- true
	}()

	for {
		select {
		case <-done:
			fmt.Println("Done!")
			return
		case t := <-ticker.C:
			fmt.Println("Current time: ", t)
		}
	}
	// section: main
}
