title: How to loop a function till a new mqtt message arrives?
body: <p>I'm writing a mqtt app in C++ with Paho. I'm using Paho.mqtt C library that can be found <a href="http://www.eclipse.org/paho/files/mqttdoc/Cclient/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>When I receive a message in the callback function, it calls another function to print the message. I want to be able to loop that function until a new message arrives.</p>
  
  <pre><code>bool start = false;
  void loopMessage(std::string message){
     start = true;
     while(start){
         std::out &lt;&lt; "message: " &lt;&lt; message;
     }
  }
  int messageArrivedCallback(mqtt message){
     start = false;
     loopMessage(message);
  }
  </code></pre>
  
  <p>The code above is not working; I can receive one message and run the while loop in the <code>loopMessage</code> function. After that the client disconnects. I think this is because it is in blocking mode and the broker disconnects the client after the keep alive interval (I'm using MQTTClient). If I quickly send a new message before disconnection, the client doesn't receive it.</p>
  
  <p>I tried to use the asynchronus client version (MQTTAsync) but it is giving me the same problem.</p>
  
  <p>Any suggestions on how to do this?</p>