30 lines
386 B
Go
30 lines
386 B
Go
package tickers
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func Tickers() {
|
|
t := time.NewTicker(500 * time.Millisecond)
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
for {
|
|
select {
|
|
case <-done:
|
|
return
|
|
case val := <-t.C:
|
|
fmt.Printf("tick at %v\n", val)
|
|
}
|
|
}
|
|
}()
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
fmt.Println("Stopping ticking")
|
|
t.Stop()
|
|
done <- true
|
|
fmt.Println("Program exiting")
|
|
}
|