Skip to content

Instantly share code, notes, and snippets.

@gocs
Created April 8, 2019 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocs/ba5aa68e94e46e46dfa43ebe862a6869 to your computer and use it in GitHub Desktop.
Save gocs/ba5aa68e94e46e46dfa43ebe862a6869 to your computer and use it in GitHub Desktop.
goroutine with channels life cycle
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