How to pause the execution of current Goroutine? Last Updated : 28 Aug, 2019 Comments Improve Suggest changes Like Article Like Report A Goroutine is a function or method which executes independently and simultaneously in connection with any other Goroutines present in your program. Or in other words, every concurrently executing activity in Go language is known as a Goroutines. So in Go language, you are allowed to pause the execution of the current goroutine by using Sleep() function. This function pauses the current goroutine for at least the specified duration, after completing the specified duration the goroutine wakes up automatically and resume its working. If the value of this function is negative or zero then this function return immediately. It is defined under the time package so, you have to import time package in your program for accessing Sleep function. Syntax: func Sleep(d_value Duration) Here, d_value represents the time duration in which you want to sleep the current goroutine. It may be in Seconds, Milliseconds, Nanoseconds, Microseconds, Minutesm, etc. Let us discuss this concept with the help of the given examples: Example 1: C // Go program to illustrate how // to put a goroutine to sleep package main import ( "fmt" "time" ) func show(str string) { for x := 0; x < 4; x++ { time.Sleep(300 * time.Millisecond) fmt.Println(str) } } // Main Function func main() { // Calling Goroutine go show("Hello") // Calling function show("GeeksforGeeks") } Output: Hello GeeksforGeeks GeeksforGeeks Hello Hello GeeksforGeeks GeeksforGeeks Example 2: C // Go program to illustrate how // to put a goroutine to sleep package main import ( "fmt" "time" ) // Here, the value of Sleep function is zero // So, this function return immediately. func show(str string) { for x := 0; x < 4; x++ { time.Sleep(0 * time.Millisecond) fmt.Println(str) } } // Main Function func main() { // Calling Goroutine go show("Hello") // Calling function show("Bye") } Output: Bye Bye Bye Bye Comment More infoAdvertise with us Next Article How to pause the execution of current Goroutine? A ankita_saini Follow Improve Article Tags : Go Language Golang Golang-Concurrency Similar Reads Using Goroutines to Execute Concurrent MySQL Queries in Go Concurrency in Go allows for the execution of multiple tasks at the same time. This feature is especially powerful when working with databases, where isolated queries can be run independently to greatly improve performance. In this article, we'll explore how Goâs concurrency through goroutines can b 5 min read How to pass a Slice to Function in Golang? In Go, slices are dynamically sized arrays. They are often passed to functions when you want to manipulate or process collections of data. Slices are passed by reference, meaning that any modification made to the slice inside the function will affect the original slice outside the function.Examplepa 4 min read How to Manage Goroutine Resources in Golang? A goroutine is a lightweight, concurrent execution unit in Go, managed by the Go runtime. It is much lighter than a thread, allowing thousands or even millions to run efficiently. Goroutines execute concurrently and are scheduled automatically, making concurrent programming in Go simple and efficien 6 min read Goroutines - Concurrency in Golang Goroutines in Go let functions run concurrently, using less memory than traditional threads. Every Go program starts with a main Goroutine, and if it exits, all others stop.Examplepackage mainimport "fmt"func display(str string) { for i := 0; i < 3; i++ { fmt.Println(str) }}func main() { go displ 2 min read How to Create Modules in Golang? Go has included support for versioned modules as proposed here since 1.11 with the initial prototype as vgo. The concept of modules in Go was introduced to handle the problem of dependencies within your Go applications. Several packages are collected and combined to form a module which is stored in 3 min read Like