Skip to content

Instantly share code, notes, and snippets.

@hallazzang
Created March 6, 2024 08:03
Show Gist options
  • Save hallazzang/e4e9a2a00fa5db79fb80a5b9e9e753e0 to your computer and use it in GitHub Desktop.
Save hallazzang/e4e9a2a00fa5db79fb80a5b9e9e753e0 to your computer and use it in GitHub Desktop.
Similar to time.Ticker but fires immediately.
import (
"log"
"time"
)
func main() {
const d = 3 * time.Second
t := time.NewTimer(0)
defer t.Stop()
for {
// You can also use `select` here for `context.Context`
<-t.C
t.Reset(d)
log.Println("fire!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment