Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Last active January 15, 2016 03:42
Show Gist options
  • Save hackintoshrao/ed8e84150e2fb320b6f7 to your computer and use it in GitHub Desktop.
Save hackintoshrao/ed8e84150e2fb320b6f7 to your computer and use it in GitHub Desktop.
Simple function called concurrently
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