1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 02:30:39 +08:00

notifier: go todo

This commit is contained in:
Juan Batiz-Benet
2015-01-26 16:45:43 -08:00
parent 2c13280b5e
commit d39feeb5a5

View File

@ -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()