counter := 0 counterChan := make(chan int) ticker := time.NewTicker(time.Duration(time.Second * 1)) go func () { for range ticker.C { counter++ fmt.Println(counter) if counter == 5 { counterChan <- counter } } }() if ch := <- counterChan; ch == 5 { fmt.Println("counter", counter) ticker.Stop() } fmt.Println("Done")ticker := time.NewTicker(20 * time.Second) for range ticker.C { // Do Stuff } ticker.Stop()