Golang time.Tick() is a utility wrapper for NewTicker
function. It only allows access to the ticking channel. Tickers are used to do something frequently at regular intervals of the stated time.
The time.Tick() is part of the time package that creates a new channel that sends the current time at fixed intervals. This function is helpful when you want to execute some action repeatedly at regular intervals.
The channel created over time.Tick() function will continue to tick indefinitely. To release the resources associated with the ticker, consider using time.NewTicker() instead returns a Ticker object that you can stop when it’s no longer needed.
Syntax
func Tick(d Duration) <-chan Time
Parameters
It takes a Duration as an argument.
Return value
It returns a receive-only channel (<-chan Time) that sends a Time value at specified intervals.
Example 1
package main
import (
"fmt"
"time"
)
func main() {
tick := time.Tick(1 * time.Second)
for currentTime := range tick {
fmt.Println("Current time:", currentTime)
}
}
Output
Current time: 2023-03-18 01:27:15.817433 +0530 IST m=+1.001282167
Current time: 2023-03-18 01:27:16.817462 +0530 IST m=+2.001326084
Current time: 2023-03-18 01:27:17.817404 +0530 IST m=+3.001282501
Current time: 2023-03-18 01:27:18.817373 +0530 IST m=+4.001267834
Current time: 2023-03-18 01:27:19.817356 +0530 IST m=+5.001264917
In this example, we created a ticker using time.Tick() function with a 1-second interval.
The for loop ranges over the channel returned by time.Tick() function and prints the current time at each tick. This loop will run indefinitely, printing the current time every second.
Example 2
package main
import (
"fmt"
"time"
)
func periodicTask() {
fmt.Println("Periodic task executed at", time.Now())
}
func main() {
ticker := time.Tick(2 * time.Second)
for {
select {
case <-ticker:
periodicTask()
}
}
}
Output
Periodic task executed at 2023-03-18 01:35:11.649779 +0530 IST m=+2.001321209
Periodic task executed at 2023-03-18 01:35:13.649864 +0530 IST m=+4.001436834
Periodic task executed at 2023-03-18 01:35:15.649728 +0530 IST m=+6.001331168
Periodic task executed at 2023-03-18 01:35:17.64971 +0530 IST m=+8.001343918
Periodic task executed at 2023-03-18 01:35:19.649669 +0530 IST m=+10.001332668
In this example, we defined a function called periodicTask() that prints a message along with the current time.
We created a ticker using time.Tick() with a 2-second interval. Inside the for loop, we use a select statement to wait for a tick from the ticker channel.
When a tick is received, the periodicTask() function is called, executing the task. This loop will run indefinitely, calling the periodicTask() function every 2 seconds.
That’s it.

Krunal Lathiya is a Software Engineer with over eight years of experience. He has developed a strong foundation in computer science principles and a passion for problem-solving. In addition, Krunal has excellent knowledge of Distributed and cloud computing and is an expert in Go Language.