Golang channel 通道常见使用场景
ok:=range exitChan{ fmt.Println(ok) } } 管道实现定时通知 func Notice(d time.Duration) chan bool { c := make(chan bool, 1) go func() { time.Sleep(d) //定时 c <- true }() close(c) return c } func main() { log.Println("one") <-Notice(time.Second) //管道没有写则阻塞 log.Println("tow") <-Notice(time.Second) log.Println("three") } 管道实现互斥锁 package main import ( "log" "time...阅读全文