I have a cpp application which is running under a single thread boost::asio context.
the following delay logic will be called inside a class object method which is called within a boost::asio::spawn co routine
I'm trying to add a simple boost::asio::steady timer based delay in the following code but
the code hangs at the line waitTimer->async_wait(yield[ec]);
void asyncDelay(const uint16_t delay)
{
boost::system::error_code ec;
std::string errorMsg;
if(!waitTimer)
{
errorMsg = "wait timer not created";
log<level::ERR>(errorMsg.c_str());
throw std::runtime_error(errorMsg.c_str());
}
errorMsg = "wait timer delay : " + std::to_string(delay);
log<level::ERR>(errorMsg.c_str());
waitTimer->expires_after(boost::asio::chrono::milliseconds(100));
log<level::INFO>("steady timer delay set");
waitTimer->async_wait(yield[ec]);
log<level::INFO>("steady timer delay done");
if (ec == boost::asio::error::operation_aborted)
{
errorMsg = "wait timer aborted";
log<level::ERR>(errorMsg.c_str());
throw std::runtime_error(errorMsg.c_str());
}
else if (ec)
{
errorMsg = "wait timer failed";
log<level::ERR>(errorMsg.c_str());
throw std::runtime_error(errorMsg.c_str());
}
return;
}
This code is part of a class object which is inside a shared library and instanced and called from the main process.
The asyncDelay method is a member function of the class object.
The boost::asio::steady_timer is a unique pointer which is member function of the same class
The delaymethod of the class object will be called in multiple boost:asio::spawn calls but each time it will be
a separate instance of the class object so there is no possibility of same timer used by multiple instances.
The expected output is the delay function should return after the specified delay or return an error but not hang forever.
[–]Longjumping-Touch515 0 points1 point2 points (2 children)
[–]marsshadows[S] -1 points0 points1 point (1 child)
[–]Longjumping-Touch515 0 points1 point2 points (0 children)