How to register a controller with coroutines C++20 #2402
-
|
Hi. I'm currently experiencing an issue registering a controller with a return type - drogon::Taskdrogon::HttpResponsePtr Example: To:
I tried registering it manually through a method, passing it as a static method. I also tried a workaround using a lambda function that already calls my controllers, but none of this worked. From the documentation I only found a code example Link on doc - https://github.com/drogonframework/drogon/wiki/ENG-17-Coroutines This doesn't work for me. Please help me register these controllers correctly. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@capybaracplusplus you should declare your methods like follows: drogon::Task<drogon::HttpResponsePtr> createShortLink(drogon::HttpRequestPtr req);
drogon::Task<drogon::HttpResponsePtr> redirectToOriginal(drogon::HttpRequestPtr req,
std::string hash);The reason is explained in the document you pasted: |
Beta Was this translation helpful? Give feedback.
@capybaracplusplus you should declare your methods like follows:
The reason is explained in the document you pasted:
Passing most parameters by value is a direct consequence of coroutines being asynchronous. It's impossible to track when a reference goes out of scope as the object may destruct while the coroutine is waiting. Or the reference may live on another thread. Thus, it may destruct while the coroutine is executing.