Created
March 6, 2024 08:03
-
-
Save hallazzang/e4e9a2a00fa5db79fb80a5b9e9e753e0 to your computer and use it in GitHub Desktop.
Similar to time.Ticker but fires immediately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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