Created
November 13, 2018 05:23
-
-
Save nikita8/37e28e454a16721dd52310c7d9185cf9 to your computer and use it in GitHub Desktop.
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
package main | |
import( | |
"fmt" | |
"time" | |
) | |
func f(from string) { | |
for i := 0; i < 3; i++ { | |
time.Sleep(1 * time.Millisecond) | |
fmt.Println(from, ":", i) | |
} | |
} | |
func main() { | |
// executing the function in another goroutine concurrently with the main. | |
go f("goroutine") | |
// calling synchronously | |
// processing in current main thread | |
f("main") | |
fmt.Println("done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment