Add tickers
This commit is contained in:
29
tickers/tickers.go
Normal file
29
tickers/tickers.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user