Use time.Sleep to pause the current goroutine for a specified duration without blocking other goroutines.
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Starting...")
time.Sleep(2 * time.Second)
fmt.Println("Resumed after 2 seconds")
}
For testing, use testing/synctest.Sleep to combine time.Sleep with testing/synctest.Wait for deterministic behavior.