```
package main
import (
"fmt"
"time"
"sync"
)
var wg sync.WaitGroup
var c chan int
func f() {
defer wg.Done()
c = make(chan int, 1)
time.Sleep(2 * time.Second)
c <- 1
}
func main() {
wg.Add(1)
go f()
select {
case m := <-c:
fmt.Println(m)
case <-time.After(10 * time.Second):
fmt.Println("timed out")
}
wg.Wait()
}
```
有疑问加站长微信联系(非本文作者)