Standard library / time

time.NewTicker()

Start periodic delivery with positive interval; nonpositive intervals panic. Slow receivers may miss ticks. Stop when periodic work is finished. On Go 1.23, channel-timer rules depend on the main module go directive and GODEBUG=asynctimerchan; see compatibility notes. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func NewTicker(d Duration) *Ticker

Parameters & Attributes

NameTypeDescription
dDurationElapsed duration or interval.

Return Value

*Ticker

Start periodic delivery with positive interval; nonpositive intervals panic.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func main() {  ticker := time.NewTicker(time.Millisecond)  defer ticker.Stop()  fmt.Println(!(<-ticker.C).IsZero())}
Go Reference