To pause the execution of a present program in Go, delay code execution, and anticipate a specified time frame, you simply want to make use of the Sleep()
perform outlined within the time package deal. As an argument, this perform takes a variable of kind time.Period
, which is the period of time this system execution needs to be stopped for. It may be expressed as a quantity multiplied by a unit fixed. For instance 3*time.Second
signifies that the execution might be stopped for 3 seconds. Obtainable items are:
time.Nanosecond
time.Microsecond
time.Millisecond
time.Second
time.Minute
time.Hour
package deal most important
import (
"fmt"
"time"
)
func most important() {
fmt.Println("earlier than Sleep()")
time.Sleep(3 * time.Second)
fmt.Println("waking up after Sleep()")
}