Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about blocking behavior in docs of Subscribe() #428

Merged
merged 3 commits into from Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions client.go
Expand Up @@ -656,6 +656,11 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac

// Subscribe starts a new subscription. Provide a MessageHandler to be executed when
// a message is published on the topic provided.
//
// Please note: you should try to keep the execution time of the callback to be
// as low as possible, especially when SetOrderMatters(true) (the default) is in
// place. Blocking calls in message handlers might otherwise delay delivery to
// other message handlers.
func (c *client) Subscribe(topic string, qos byte, callback MessageHandler) Token {
token := newToken(packets.Subscribe).(*SubscribeToken)
DEBUG.Println(CLI, "enter Subscribe")
Expand Down
1 change: 1 addition & 0 deletions options.go
Expand Up @@ -209,6 +209,7 @@ func (o *ClientOptions) SetCleanSession(clean bool) *ClientOptions {
// each QoS level. By default, this value is true. If set to false,
// this flag indicates that messages can be delivered asynchronously
// from the client to the application and possibly arrive out of order.
// Specifically, the message handler is called in its own go routine.
func (o *ClientOptions) SetOrderMatters(order bool) *ClientOptions {
o.Order = order
return o
Expand Down
6 changes: 2 additions & 4 deletions router.go
Expand Up @@ -168,10 +168,8 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
}
r.RUnlock()
for _, handler := range handlers {
func() {
handler(client, m)
m.Ack()
}()
handler(client, m)
m.Ack()
}
// DEBUG.Println(ROU, "matchAndDispatch handled message")
}
Expand Down