Standard library / time

time.Timer

One-shot timer created by NewTimer or AfterFunc. C is nil for AfterFunc; Stop and Reset have version-specific contracts. Expected stdout: 'fired\n'.

Formal Syntax & Structure

go syntaxgo
type Timer struct { C <-chan Time; /* unexported fields */ }

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func main() { t := time.NewTimer(0); defer t.Stop(); <-t.C; fmt.Println("fired") }
Go Reference