Skip to content

Instantly share code, notes, and snippets.

@yusufpapurcu
Created October 12, 2021 17:47
Show Gist options
  • Save yusufpapurcu/797638f6248b01ef2ba0bfb2400d783b to your computer and use it in GitHub Desktop.
Save yusufpapurcu/797638f6248b01ef2ba0bfb2400d783b to your computer and use it in GitHub Desktop.
func main() {
// This will block for 5 seconds and then return the current time
theTime := <-time.After(time.Second * 5)
fmt.Println(theTime.Format("2006-01-02 15:04:05"))
}
func main() {
// Set when we want to continue
until, _ := time.Parse(time.RFC3339, "2023-01-01T00:00:01+02:00")
// Wait until it
<-time.After(time.Until(until))
}
func main() {
// This will print the time every 5 seconds
for theTime := range time.Tick(time.Second * 5) {
fmt.Println(theTime.Format("2006-01-02 15:04:05"))
}
}
func main() {
for {
select {
// This usage will ignore actual time
// Just runs in every 5 second
case <-time.Tick(time.Second * 5):
fmt.Println("I'm a bot that saying 'You are amazing' in every 5 second")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment