we can use channels to sychronize execution across goroutines. Here's an example of using a blocking receive to to wait for a goroutine to finsh
package main import ( "fmt" "time" ) func worker(done chan bool) { fmt.Println("working..") time.Sleep(time.Second) fmt.Println("done") done <- true } func main() { done := make(chan bool, 1) go worker(done) fmt.Println("done", <-done) fmt.Println(<-done) }
working.. done done true
总结 :
1 : .......
有疑问加站长微信联系(非本文作者)