Skip to content

Commit 3c2803b

Browse files
committed
Improved rumqttc event loop check.
Signed-off-by: Suneet Nangia <[email protected]>
1 parent ca6b061 commit 3c2803b

File tree

1 file changed

+24
-9
lines changed
  • crates/outbound-mqtt/src

1 file changed

+24
-9
lines changed

crates/outbound-mqtt/src/lib.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,31 @@ impl v2::HostConnection for OutboundMqtt {
9797
.await
9898
.map_err(other_error)?;
9999

100-
// Poll EventLoop once to send the message to MQTT broker or capture/throw error
100+
// Poll event loop until outgoing publish event is iterated over to send the message to MQTT broker or capture/throw error.
101101
// We may revisit this later to manage long running connections and their issues in the connection pool.
102-
eventloop
103-
.poll()
104-
.await
105-
.map_err(|err: rumqttc::ConnectionError| {
106-
v2::Error::ConnectionFailed(err.to_string())
107-
})?;
108-
109-
Ok(())
102+
loop {
103+
let event = eventloop
104+
.poll()
105+
.await
106+
.map_err(|err| v2::Error::ConnectionFailed(err.to_string()))?;
107+
108+
match event {
109+
rumqttc::Event::Outgoing(outgoing_event) => {
110+
match outgoing_event {
111+
rumqttc::Outgoing::Publish(_) => {
112+
return Ok(());
113+
}
114+
_ => {
115+
// We don't care about other outgoing event types in this loop check.
116+
continue;
117+
}
118+
}
119+
}
120+
rumqttc::Event::Incoming(_) => {
121+
// We don't care about incoming event types in this loop check.
122+
}
123+
}
124+
}
110125
}
111126
.await)
112127
}

0 commit comments

Comments
 (0)