Programming Code Center(PCC)
[GO]

(PCC)::[How-to-use-the-select-builtin-on-the-channel-to-await-the-values-as-they-arrive-every-500ms-using-Tickers-in-go-language]::[go]

File Name : tickers.go

package main

import (
    "fmt"
    "time"
)

func main() {

    ticker := time.NewTicker(500 * time.Millisecond)
    done := make(chan bool)

    go func() {
        for {
            select {
            case <-done:
                return
            case t := <-ticker.C:
                fmt.Println("Tick at", t)
            }
        }
    }()

    time.Sleep(1600 * time.Millisecond)
    ticker.Stop()
    done <- true
    fmt.Println("Ticker stopped")
}

Output :

tickers.jpg