Golang time.Sleep() function example
package time
Golang time.Sleep() function usage example
package main
import (
"fmt"
"time"
)
func delaySecond(n time.Duration) {
time.Sleep(n * time.Second) // <------------ here
}
func delayMinute(n time.Duration) {
time.Sleep(n * time.Minute)
}
func main() {
fmt.Println("starts")
delaySecond(3) // delay 3 seconds
fmt.Println("after 3 second")
delayMinute(1) // delay 1 minute
fmt.Println("after 1 minute delay... now get back to work!")
}
Reference :
Advertisement
Something interesting
Tutorials
+12.7k Golang : zlib compress file example
+14.2k Golang : syscall.Socket example
+6.7k Golang : Reverse by word
+18.8k Golang : How to make function callback or pass value from function as parameter?
+17.9k Golang : Qt image viewer example
+7.1k Golang : Validate credit card example
+10.5k Generate Random number with math/rand in Go
+10.5k Swift : Convert (cast) String to Integer
+7.5k Golang : Get YouTube playlist
+33.7k Golang : All update packages with go get command
+31.9k Golang : Convert an image file to []byte