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.
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:
Hello GeeksforGeeks GeeksforGeeks Hello Hello GeeksforGeeks GeeksforGeeks
Bye Bye Bye Bye
- Golang | Goroutine vs Thread
- How to Get Current Weekday in Golang?
- How to Get Current time in Golang?
- How to Get the Current Working Directory in Golang?
- How Many Logical Processors Used By Current Process in Golang?
- How to Get Current Date and Time in Various Format in Golang?
- Getting the current date and time with timestamp in local and other timezones in Golang
- Python vs Other Programming Languages
- How to Uncompress a File in Golang?
- How to Create Your Own Package in Golang?
- Import in GoLang
- Switch Case with Break in For Loop in Golang
- Golang - GOPATH and GOROOT
- string package in Golang
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.