1 #include <boost/asio.hpp> 2 3 #include <chrono> 4 #include <functional> 5 6 namespace 7 { 8 // Set the read loop interval to be 1 second for now 9 // TODO: Make this a configuration option 10 static constexpr std::chrono::seconds readIntervalSec(1); 11 } // namespace 12 13 // boost::async_wait requires `const boost::system::error_code&` parameter 14 void readLoop(boost::asio::steady_timer* t, const boost::system::error_code&) 15 { 16 /* This will run every readIntervalSec second for now */ 17 t->expires_from_now(readIntervalSec); 18 t->async_wait(std::bind_front(readLoop, t)); 19 } 20 21 int main() 22 { 23 boost::asio::io_context io; 24 boost::asio::steady_timer t(io, readIntervalSec); 25 26 t.async_wait(std::bind_front(readLoop, &t)); 27 28 io.run(); 29 30 return 0; 31 } 32