package main import ( "fmt" "time" ) func main() { stop := make(chan struct{}) go func() { select { case <-stop: fmt.Println("worker 收到停止信号,退出") } }() time.Sleep(2 * time.Second) fmt.Println("main: 关闭 stop channel") close(stop) time.Sleep(1 * time.Second) }