Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,426
- Solutions
- 68
- Reaction score
- 1,075
How hard is it to implement async database calls? It seems pretty easy based on what I have read. What things should I consider? I have created this code which theoretically will execute a query async. What problems could happen from this?
Then to get and do something with the result after it returns:
C++:
std::future<bool> Database::executeAsyncQuery(const std::string& query)
{
return std::async(std::launch::async, [this, query] { return executeQuery(query); });
}
Then to get and do something with the result after it returns:
C++:
std::future<bool> resultFuture = Database::getInstance().executeAsyncQuery("SELECT * FROM users");
if (resultFuture.get()) {
std::cout << "Query executed successfully!" << std::endl;
} else {
std::cerr << "Query execution failed!" << std::endl;
}