Files
learn-golang/go-atomic-cpu/cpu_channel_wait.go
2025-12-26 17:56:02 +08:00

24 lines
303 B
Go

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)
}