Created
April 8, 2019 14:19
-
-
Save gocs/ba5aa68e94e46e46dfa43ebe862a6869 to your computer and use it in GitHub Desktop.
goroutine with channels life cycle
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" | |
func do_stuff(done chan bool) { | |
fmt.Println("2") | |
done <- true | |
fmt.Println("3") | |
} | |
func main() { | |
done := make(chan bool) | |
go do_stuff(done) | |
fmt.Println("1") | |
<-done // forces `do_stuff` to do job | |
fmt.Println("4") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment