3 examples of sleeping in Go
Onelinerhub
Posted on July 21, 2022
In order to sleep, we need time
lib. Simplest case, when we want to sleep for a single second, we do it like:
package main
import "time"
func main() {
// ...
time.Sleep(time.Second)
// ...
}
Sleep for seconds
In order to sleep for several seconds, we multiple by the amount of second we need. E.g. to sleep for 10 seconds:
package main
import "time"
func main() {
// ...
time.Sleep(10 * time.Second)
// ...
}
Sleep for milliseconds
time.Millisecond
can be used to sleep for X
milliseconds:
package main
import "time"
func main() {
// ...
time.Sleep(50 * time.Millisecond)
// ...
}
💖 💪 🙅 🚩
Onelinerhub
Posted on July 21, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.