mqtt: reduce use of goroutines in router to not start a new goroutine for each invocation of each callback

Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2020-04-07 01:19:58 +02:00
parent 6f213e97c3
commit 1987f424ad
+4 -8
View File
@@ -150,10 +150,8 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
handlers = append(handlers, e.Value.(*route).callback) handlers = append(handlers, e.Value.(*route).callback)
} else { } else {
hd := e.Value.(*route).callback hd := e.Value.(*route).callback
go func() { hd(client, m)
hd(client, m) //TODO: m.Ack()
//TODO: m.Ack()
}()
} }
sent = true sent = true
} }
@@ -162,10 +160,8 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
if order { if order {
handlers = append(handlers, r.defaultHandler) handlers = append(handlers, r.defaultHandler)
} else { } else {
go func() { r.defaultHandler(client, m)
r.defaultHandler(client, m) //TODO: m.Ack()
//TODO: m.Ack()
}()
} }
} }
for _, handler := range handlers { for _, handler := range handlers {