Channel synchronization
Context
Section titled “Context”You can use channels to synchronize execution between goroutines. A blocking receive can wait for a goroutine to finish.
Example
Section titled “Example”Use a channel to wait for a goroutine to complete its work.
Code example
Section titled “Code example”package main
import ( "fmt" "time")
func worker(done chan bool) { fmt.Print("working...") time.Sleep(1 * time.Second) fmt.Println("done") done <- true}
func main() { done := make(chan bool) go worker(done) <-done // wait}Output
Section titled “Output”working...done