Skip to content

Commit 939b85e

Browse files
committed
update changes inline with requested changes
1 parent 3c600de commit 939b85e

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ func (c *client) reconnect() {
345345
)
346346

347347
for rc != 0 && c.status != disconnected {
348-
if nil != c.options.OnWillReconnect {
349-
c.options.OnWillReconnect(c, WillReconnectArgs{&c.options})
348+
if nil != c.options.OnReconnecting {
349+
c.options.OnReconnecting(c, &c.options)
350350
}
351351
for _, broker := range c.options.Servers {
352352
cm := newConnectMsgFromOptions(&c.options, broker)

options.go

+7-14
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,9 @@ type ConnectionLostHandler func(Client, error)
4444
// at initial connection and on reconnection
4545
type OnConnectHandler func(Client)
4646

47-
// WillReconnectArgs contains parameters relating to reconnection
48-
type WillReconnectArgs struct {
49-
// Options points to the current client options. You may want
50-
// to update authentication credentials etc prior to reconnection attempt
51-
Options *ClientOptions
52-
}
53-
54-
// WillReconnectHandler is invoked prior to a reconnecting after
47+
// ReconnectHandler is invoked prior to reconnecting after
5548
// the initial connection is lost
56-
type WillReconnectHandler func(Client, WillReconnectArgs)
49+
type ReconnectHandler func(Client, *ClientOptions)
5750

5851
// ClientOptions contains configurable options for an Client.
5952
type ClientOptions struct {
@@ -81,7 +74,7 @@ type ClientOptions struct {
8174
DefaultPublishHandler MessageHandler
8275
OnConnect OnConnectHandler
8376
OnConnectionLost ConnectionLostHandler
84-
OnWillReconnect WillReconnectHandler
77+
OnReconnecting ReconnectHandler
8578
WriteTimeout time.Duration
8679
MessageChannelDepth uint
8780
ResumeSubs bool
@@ -305,10 +298,10 @@ func (o *ClientOptions) SetConnectionLostHandler(onLost ConnectionLostHandler) *
305298
return o
306299
}
307300

308-
// SetWillReconnectHandler will set the OnWillReconnect callback to be executed prior
309-
// to the client attempting a reconnect to the MQTT brokers.
310-
func (o *ClientOptions) SetWillReconnectHandler(onWillReconnect WillReconnectHandler) *ClientOptions {
311-
o.OnWillReconnect = onWillReconnect
301+
// SetReconnectingHandler sets the OnReconnecting callback to be executed prior
302+
// to the client attempting a reconnect to the MQTT broker.
303+
func (o *ClientOptions) SetReconnectingHandler(cb ReconnectHandler) *ClientOptions {
304+
o.OnReconnecting = cb
312305
return o
313306
}
314307

0 commit comments

Comments
 (0)