提交 d39feeb5 作者: Juan Batiz-Benet

notifier: go todo

上级 2c13280b
...@@ -99,14 +99,16 @@ func (n *Notifier) StopNotify(e Notifiee) { ...@@ -99,14 +99,16 @@ func (n *Notifier) StopNotify(e Notifiee) {
// }) // })
// } // }
// //
// Note well: each notification is launched in its own goroutine, so they
// can be processed concurrently, and so that whatever the notification does
// it _never_ blocks out the client. This is so that consumers _cannot_ add
// hooks into your object that block you accidentally.
func (n *Notifier) NotifyAll(notify func(Notifiee)) { func (n *Notifier) NotifyAll(notify func(Notifiee)) {
n.mu.Lock() n.mu.Lock()
if n.nots != nil { // so that zero-value is ready to be used. if n.nots != nil { // so that zero-value is ready to be used.
for notifiee := range n.nots { for notifiee := range n.nots {
// we spin out a goroutine so that whatever the notification does
// it _never_ blocks out the client. This is so that consumers
// _cannot_ add hooks into your object that block you accidentally.
go notify(notifiee) go notify(notifiee)
// TODO find a good way to rate limit this without blocking notifier.
} }
} }
n.mu.Unlock() n.mu.Unlock()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论