Standard library / time
time.NewTimer()
Create a one-shot timer and receive from C; use Stop to cancel pending work. Timer semantics depend on module version and GODEBUG. 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 NewTimer(d Duration) *TimerParameters & Attributes
| Name | Type | Description |
|---|---|---|
| d | Duration | Elapsed duration or interval. |
Return Value
*Timer
Create a one-shot timer and receive from C; use Stop to cancel pending work.
Working Example
Example Snippetgo
package main
import ( "fmt" "time")
func main() { timer := time.NewTimer(0); defer timer.Stop(); fmt.Println(!(<-timer.C).IsZero()) }