var timeOutDuration =, time.Minute * 10,
func main (), {
list :=, Newlist ()
rid :=, uint64 (time.Now () .UnixNano ())
go func (), {
ch :=, list.Register(去掉)
fmt.Println (“start 注册:“去掉)
if ch ==, nil {
返回
}
select {
case x :=, & lt;作用;ch:
fmt.Printf (“trigger 配套;id: % d x: % v \ n",摆脱,x)
case & lt;还(timeOutDuration):
log.Println (“timeout 错误:“,去掉)
}
} ()
time . sleep (time.Second)
,
rid2 :=, uint64 (time.Now () .UnixNano ())
go func (), {
ch :=, list.Register (rid2)
fmt.Println (“start 注册:“rid2)
if ch ==, nil {
返回
}
select {
case x :=, & lt;作用;ch:
fmt.Printf (“trigger 配套;id: % d x: % v \ n", rid2, x)
case & lt;还(timeOutDuration):
log.Println (“timeout 错误:“,rid2)
}
} ()
,
go func (), {
time . sleep (time.Second * 5)
list.Trigger(去掉“Hello")
time . sleep (time.Second * 3)
list.Trigger (rid2“World")
} ()
,
select {
,
}
}
<>强补充:去程序等待一段时间执行
我就废话不多说了,大家还是直接看代码吧~
package 主要
import (
,“fmt"
,“time"
)
func main (), {
,fmt.Println (time.Now ())//等1秒
,time . sleep (time.Second *, 1)
,fmt.Println (time.Now ())//等1秒
还勉强,& lt (time.Second *, 1)
,fmt.Println (time.Now ())
}