Golang Code

Sleeping in Go – How to Pause Execution

· 64 words · 1 minute read #seconds #sleep #sleeping #time #unix #wait

Sleeping, or waiting in Go, is part of the time package. It’s a very simple process, all you need to do is specify the duration to sleep for, which in this cases is a number followed by it’s unit.

package main

import (
    "fmt"
    "time"
)

func main() {

    fmt.Printf("Current Unix Time: %v\n", time.Now().Unix())

    fmt.Println("Sleeping...")

    time.Sleep(2 * time.Second)

    fmt.Printf("Current Unix Time: %v\n", time.Now().Unix())

}

See something which isn't right? You can contribute to this page on GitHub or just let us know in the comments below. Thanks for reading!