mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-22 19:33:27 +01:00
Call subscriber funtions in individual goroutines
This commit is contained in:
parent
ed9d99fd57
commit
9cee8ab888
1 changed files with 7 additions and 3 deletions
|
@ -50,9 +50,13 @@ func (t *topic) Publish(v *visitor, m *message) error {
|
||||||
if len(subscribers) > 0 {
|
if len(subscribers) > 0 {
|
||||||
log.Debug("%s Forwarding to %d subscriber(s)", logMessagePrefix(v, m), len(subscribers))
|
log.Debug("%s Forwarding to %d subscriber(s)", logMessagePrefix(v, m), len(subscribers))
|
||||||
for _, s := range subscribers {
|
for _, s := range subscribers {
|
||||||
if err := s(v, m); err != nil {
|
// We call the subscriber functions in their own Go routines because they are blocking, and
|
||||||
log.Warn("%s Error forwarding to subscriber", logMessagePrefix(v, m))
|
// we don't want individual slow subscribers to be able to block others.
|
||||||
}
|
go func(s subscriber) {
|
||||||
|
if err := s(v, m); err != nil {
|
||||||
|
log.Warn("%s Error forwarding to subscriber", logMessagePrefix(v, m))
|
||||||
|
}
|
||||||
|
}(s)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Trace("%s No stream or WebSocket subscribers, not forwarding", logMessagePrefix(v, m))
|
log.Trace("%s No stream or WebSocket subscribers, not forwarding", logMessagePrefix(v, m))
|
||||||
|
|
Loading…
Reference in a new issue