crow icon indicating copy to clipboard operation
crow copied to clipboard

Send response from another thread

Open KweonYongJae opened this issue 6 years ago • 1 comments

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());	
	...
}

KweonYongJae avatar Oct 28 '19 03:10 KweonYongJae

@kokonoki Try using boost::asio IO_Service / IO_Context for this... your use case fits the their description perfectly.

Pipe-Runner avatar Feb 03 '20 14:02 Pipe-Runner