DEV Community 👩‍💻👨‍💻

Michele Caci
Michele Caci

Posted on

TIL: Go range on time.Tick for regular tasks

Today I learned how to simply repeat a task over time with regularity in Go:

for range time.Tick(1 * time.Second) {
    fmt.Println("Hello, playground") // any task here
}
Enter fullscreen mode Exit fullscreen mode

Here's a playground example in action: https://play.golang.org/p/RUdgii5EMx7

Top comments (0)

Dream Big


Use any Linode offering to create something unique or silly in the DEV x Linode Hackathon 2022 and win the Wacky Wildcard category.

Join the Hackathon <-