Created
March 18, 2023 14:52
-
-
Save Risyandi/19aab2e98ae981127cf2d284b0390ff0 to your computer and use it in GitHub Desktop.
how to pause the execution of current go routine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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