@@ -116,7 +116,7 @@ func (MqttClientBuilder) Build(opts *mqtt.ClientOptions) mqtt.Client {
116
116
return mqtt .NewClient (opts )
117
117
}
118
118
119
- type TimeFunc func (int ) time.Duration
119
+ type CalculateRetryDelayForAttempt func (attempt int ) time.Duration
120
120
121
121
// Client is a client for Notification center
122
122
type Client struct {
@@ -128,7 +128,7 @@ type Client struct {
128
128
subjectErr events.Publisher [error ]
129
129
subjectPeerUpdate events.Publisher [[]string ]
130
130
credsFetcher CredentialsGetter
131
- timeFunc TimeFunc
131
+ retryDelayFunc CalculateRetryDelayForAttempt
132
132
133
133
startMu sync.Mutex
134
134
started bool
@@ -150,7 +150,7 @@ func NewClient(
150
150
subjectErr : subjectErr ,
151
151
subjectPeerUpdate : subjectPeerUpdate ,
152
152
credsFetcher : credsFetcher ,
153
- timeFunc : network .ExponentialBackoff ,
153
+ retryDelayFunc : network .ExponentialBackoff ,
154
154
}
155
155
}
156
156
@@ -246,6 +246,7 @@ func (c *Client) tryConnect(
246
246
select {
247
247
case managementChan <- credentials .ExpirationDate :
248
248
case <- ctx .Done ():
249
+ return client , connectionState
249
250
}
250
251
251
252
opts := c .createClientOptions (credentials , managementChan , ctx )
@@ -309,7 +310,7 @@ func (c *Client) connectWithBackoff(client mqtt.Client,
309
310
client .Disconnect (0 )
310
311
}
311
312
return client
312
- case <- time .After (c .timeFunc (tries )):
313
+ case <- time .After (c .retryDelayFunc (tries )):
313
314
}
314
315
}
315
316
0 commit comments