template<typename T>
class orbit::concurrency::Awaitable< T >
A lazy coroutine that produces a T for whoever co_awaits it.
For helpers called from a handler (or from another Awaitable), so a handler need not be one long coroutine:
auto users = co_await query_User(db).where(Col("id") == id).get_async();
if (users.empty()) co_return std::nullopt;
co_return users.front();
}
Task show_user(HttpRequest& req, std::shared_ptr<ResponseWriter> w) {
auto user = co_await load_user(db, std::stoi(req.params.at("id")));
HttpResponse res;
if (user) res.json(*user); else res.status(HttpStatus::NotFound);
w->send(std::move(res));
}
A lazy coroutine that produces a T for whoever co_awaits it.
Definition Awaitable.hpp:77
Fire-and-forget coroutine type, used as the return type of coroutine route handlers.
Definition Task.hpp:36
- Nothing runs until it is awaited; awaiting starts it on the awaiting thread, and the awaiting coroutine resumes, by symmetric transfer, on whichever thread the helper finishes on.
- An exception thrown in the helper is rethrown at the co_await. In a handler that is not caught, it reaches on_error (else a 500), exactly as if the handler had thrown it.
- Await it once. Destroying it without awaiting simply never runs it.
- Handlers themselves keep returning Task: the router starts a Task, but would never await an Awaitable.