Skip to content

Commit 92ec502

Browse files
committed
Spawn message_callback to not block eventloop.
In case the message_callback takes a long time to return, this would affect the MQTT loop (e.g. keep-alive messages are not sent / responded in time). Closes #57.
1 parent 4879cf7 commit 92ec502

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/mqtt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,13 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
218218

219219
match v {
220220
Event::Incoming(Incoming::Publish(p)) => {
221-
if let Err(e) = message_callback(p).await {
222-
error!("Handling message error, error: {}", e);
223-
}
221+
tokio::spawn({
222+
async move {
223+
if let Err(e) = message_callback(p).await {
224+
error!("Handling message error, error: {}", e);
225+
}
226+
}
227+
});
224228
}
225229
Event::Incoming(Incoming::ConnAck(v)) => {
226230
if v.code == ConnectReturnCode::Success {

0 commit comments

Comments
 (0)