drogon
drogon copied to clipboard
Add coroutines support for HttpFilter
Is your feature request related to a problem? Please describe.
Executing queries in HttpFilter
specially for redis becomes messy because of the callbacks and dependency between the queries:
Describe the solution you'd like
Add coroutines support for HttpFilter::doFilter
method.
Additional context Example:
auto redisClient = drogon::app().getFastRedisClient();
redisClient->execCommandAsync(
[fcb, redisClient, username](const drogon::nosql::RedisResult &result) {
redisClient->execCommandAsync(
[fcb, redisClient, username](const drogon::nosql::RedisResult &result) {
redisClient->execCommandAsync(
[fcb, redisClient](const drogon::nosql::RedisResult &result) {
redisClient->execCommandAsync(
[](const drogon::nosql::RedisResult &result) {
for (const auto &r : result.asArray())
LOG_DEBUG << r.asInteger();
},
[fcb](const drogon::nosql::RedisException &exception) {
returnUnauthorized(exception.what(), fcb);
},
"EXEC");
},
[fcb](const drogon::nosql::RedisException &exception) {
returnUnauthorized(exception.what(), fcb);
},
"EXPIRE qbook:%s.actions %s", username.c_str(), std::to_string(SESSION_EXPIRE_SEC).c_str());
},
[fcb](const drogon::nosql::RedisException &exception) {
returnUnauthorized(exception.what(), fcb);
},
"EXPIRE qbook:%s.session_id %s", username.c_str(), std::to_string(SESSION_EXPIRE_SEC).c_str());
},
[fcb](const drogon::nosql::RedisException &exception) {
returnUnauthorized(exception.what(), fcb);
},
"MULTI");
Does the filter support async?
auto redisClientPtr = app().getRedisClient();
transPtr->execCommandAsync(
[fccb](const nosql::RedisResult &r) {
// successed
return fccb();
},
[](const std::exception &err) { /* this command failed */ },
"del %s", auth.data());
I have tested in my project and it seems that only synchronous methods can be used.
Does the filter support async?
auto redisClientPtr = app().getRedisClient(); transPtr->execCommandAsync( [fccb](const nosql::RedisResult &r) { // successed return fccb(); }, [](const std::exception &err) { /* this command failed */ }, "del %s", auth.data());
I have tested in my project and it seems that only synchronous methods can be used.
@1111mp It does, but the filter chain callback must be running on the IO threads due to some implementation details. So you can only use fast RedisClient or fast DbClient here.