@@ -30,7 +30,7 @@ type RetryClient struct {
3030 mu sync.Mutex
3131 muQueue sync.Mutex
3232 handler Handler
33- chTask chan func (cli Client )
33+ chTask chan func (ctx context. Context , cli Client )
3434}
3535
3636// Handle registers the message handler.
@@ -46,23 +46,23 @@ func (c *RetryClient) Handle(handler Handler) {
4646// Publish tries to publish the message and immediately return nil.
4747// If it is not acknowledged to be published, the message will be queued.
4848func (c * RetryClient ) Publish (ctx context.Context , message * Message ) error {
49- return c .pushTask (ctx , func (cli Client ) {
49+ return c .pushTask (ctx , func (ctx context. Context , cli Client ) {
5050 c .publish (ctx , false , cli , message )
5151 })
5252}
5353
5454// Subscribe tries to subscribe the topic and immediately return nil.
5555// If it is not acknowledged to be subscribed, the request will be queued.
5656func (c * RetryClient ) Subscribe (ctx context.Context , subs ... Subscription ) error {
57- return c .pushTask (ctx , func (cli Client ) {
57+ return c .pushTask (ctx , func (ctx context. Context , cli Client ) {
5858 c .subscribe (ctx , false , cli , subs ... )
5959 })
6060}
6161
6262// Unsubscribe tries to unsubscribe the topic and immediately return nil.
6363// If it is not acknowledged to be unsubscribed, the request will be queued.
6464func (c * RetryClient ) Unsubscribe (ctx context.Context , topics ... string ) error {
65- return c .pushTask (ctx , func (cli Client ) {
65+ return c .pushTask (ctx , func (ctx context. Context , cli Client ) {
6666 c .unsubscribe (ctx , false , cli , topics ... )
6767 })
6868}
@@ -148,7 +148,7 @@ func (c *RetryClient) removeEstablished(topics ...string) {
148148
149149// Disconnect from the broker.
150150func (c * RetryClient ) Disconnect (ctx context.Context ) error {
151- err := c .pushTask (ctx , func (cli Client ) {
151+ err := c .pushTask (ctx , func (ctx context. Context , cli Client ) {
152152 cli .Disconnect (ctx )
153153 })
154154 close (c .chTask )
@@ -174,18 +174,19 @@ func (c *RetryClient) SetClient(ctx context.Context, cli Client) {
174174 return
175175 }
176176
177- c .chTask = make (chan func (cli Client ))
177+ c .chTask = make (chan func (ctx context. Context , cli Client ))
178178 go func () {
179+ ctx := context .Background ()
179180 for task := range c .chTask {
180181 c .mu .Lock ()
181182 cli := c .cli
182183 c .mu .Unlock ()
183- task (cli )
184+ task (ctx , cli )
184185 }
185186 }()
186187}
187188
188- func (c * RetryClient ) pushTask (ctx context.Context , task func (cli Client )) error {
189+ func (c * RetryClient ) pushTask (ctx context.Context , task func (ctx context. Context , cli Client )) error {
189190 c .mu .Lock ()
190191 chTask := c .chTask
191192 c .mu .Unlock ()
0 commit comments