Mqtt: wait for retained message after subscribe before first read (#32031)
This commit is contained in:
parent
d92f125336
commit
1656a76cb3
1 changed files with 10 additions and 0 deletions
|
|
@ -118,6 +118,16 @@ func (m *Mqtt) newReceiver() (*msgHandler, error) {
|
|||
}
|
||||
|
||||
err := m.client.Listen(m.topic, h.receive)
|
||||
|
||||
// without timeout, wait briefly for a retained message- it arrives right after suback
|
||||
if err == nil && m.timeout == 0 {
|
||||
select {
|
||||
case <-h.val.Done():
|
||||
case <-m.ctx.Done():
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
|
||||
return h, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue