Skip to content

Commit

Permalink
Spawn message_callback to not block eventloop.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brocaar committed Jul 10, 2024
1 parent 4879cf7 commit 92ec502
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ pub async fn setup(conf: &Configuration) -> Result<()> {

match v {
Event::Incoming(Incoming::Publish(p)) => {
if let Err(e) = message_callback(p).await {
error!("Handling message error, error: {}", e);
}
tokio::spawn({
async move {
if let Err(e) = message_callback(p).await {
error!("Handling message error, error: {}", e);
}
}
});
}
Event::Incoming(Incoming::ConnAck(v)) => {
if v.code == ConnectReturnCode::Success {
Expand Down

0 comments on commit 92ec502

Please sign in to comment.