Last active
January 15, 2016 03:42
-
-
Save hackintoshrao/ed8e84150e2fb320b6f7 to your computer and use it in GitHub Desktop.
Simple function called concurrently
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
//by using the go construct the function execution can be made concurrent | |
go my_sleep_func() | |
fmt.Println("Control reach here even though my_sleep_func has not finished executing") | |
fmt.Println("the intution is similar to being asynchrinous without callbacks :D") | |
//sleeping in main to make sure the main doesn't end | |
time.Sleep(6 * time.Second) | |
} | |
func my_sleep_func() { | |
//sleeps for 5 seconds | |
time.Sleep(1 * time.Second) | |
fmt.Println("My func out of sleep, but its executed concurrently") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment