Standard library / time

time.Ticker.Reset()

Stop the existing interval and set a new positive one. The next tick follows the new interval; a nonpositive duration panics. On Go 1.23, channel-timer rules depend on the main module go directive and GODEBUG=asynctimerchan; see compatibility notes. Expected stdout: 'tick\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Ticker) Reset(d Duration)

Parameters & Attributes

NameTypeDescription
dDurationElapsed duration or interval.

Working Example

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