Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created March 18, 2023 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/19aab2e98ae981127cf2d284b0390ff0 to your computer and use it in GitHub Desktop.
Save Risyandi/19aab2e98ae981127cf2d284b0390ff0 to your computer and use it in GitHub Desktop.
how to pause the execution of current go routine
// 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")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment