Golang time.Tick() function examples
package time
Golang time.Tick() function usage examples.
Example 1:
package main
import (
"fmt"
"time"
)
func echo(s string) {
fmt.Println(s)
}
func delaySecond(n time.Duration) {
for _ = range time.Tick(n * time.Second) {
str := "Hi! " + n.String() + " seconds have passed"
echo(str)
}
}
func main() {
go delaySecond(5) // very useful for interval polling
select {} // this will cause the program to run forever
}
Example 2:
func statusUpdate() string { return "" }
func ExampleTick() {
c := time.Tick(1 * time.Minute)
for now := range c {
fmt.Printf("%v %s\n", now, statusUpdate())
}
}
Reference :
Advertisement
Something interesting
Tutorials
+16.7k Golang : Gzip file example
+16.4k Golang : How to implement two-factor authentication?
+4.8k Javascript : How to get width and height of a div?
+4.8k Which content-type(MIME type) to use for JSON data
+4.7k Javascript : Access JSON data example
+9.6k Golang : Validate IPv6 example
+18.2k Golang : Get command line arguments
+10.1k Golang : How to tokenize source code with text/scanner package?
+6.1k Golang : Scan forex opportunities by Bollinger bands
+9k Golang : Capture text return from exec function example
+10.1k Golang : Compare files modify date example