1. package main
    2. import (
    3. "fmt"
    4. "time"
    5. )
    6. func main() {
    7. c := make(chan struct{}, 1)
    8. go func() {
    9. fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
    10. time.Sleep(time.Second * 5)
    11. close(c)
    12. // c <- struct{}{}
    13. }()
    14. // 等待 goroutine
    15. <-c
    16. fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
    17. }