crow
crow copied to clipboard
Send response from another thread
after receiving request () Try to process DB SP.. Is there any way to do it in other threads by putting it in a queue without doing DB processing immediately?
// Not this way.
CROW_ROUTE(m_lpWebServerBase->m_kCrowApp, "/").methods("POST"_method)([](const crow::request &_request) {
....
std::string test = DB.callSPTestSelect();
return crow::response(test.c_str());
});
// Processed in this way
CROW_ROUTE(m_lpWebServerBase->m_kCrowApp, "/").methods("POST"_method)([](const crow::request &_request) {
....
queue.push(...);
return "";
});
void DBThread()
{
...
getQueue();
std::string test = DB.callSPTestSelect();
return crow::response(test.c_str());
...
}
@kokonoki Try using boost::asio IO_Service / IO_Context for this... your use case fits the their description perfectly.