😴 Sleep function in Go - pause the program execution

introduction goroutine time

To pause the execution of a current program in Go, you just need to use Sleep() function defined in time package. As an argument, this function takes a variable of type time.Duration, which is the amount of time the program execution should be stopped for. It can be expressed as a number multiplied by a unit constant, for example 3*time.Second means that the execution will be stopped for 3 seconds. Available units are:

package main

import (

func main() {
    fmt.Println("before Sleep()")

    time.Sleep(3 * time.Second)

    fmt.Println("waking up after Sleep()")

⏲️ Measure execution time in Go

Learn how to measure the time taken by a function
introduction time

🖨️ Convert string to []byte or []byte to string in Go

Learn the difference between a string and a byte slice
introduction strings slice

🧠 Print the memory address of a variable in Go

Learn how to find and print the address of a variable or pointer
introduction pointer slice