mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-11-29 18:27:43 +08:00
Add coroutine to wait until event loop ends (#1500)
This commit is contained in:
parent
d4c0e063f1
commit
ab5259b290
@ -697,6 +697,21 @@ struct [[nodiscard]] LoopAwaiter : CallbackAwaiter<void>
|
||||
std::function<void()> taskFunc_;
|
||||
};
|
||||
|
||||
struct [[nodiscard]] EndAwaiter : CallbackAwaiter<void>
|
||||
{
|
||||
EndAwaiter(trantor::EventLoop *loop) : loop_(loop)
|
||||
{
|
||||
assert(loop);
|
||||
}
|
||||
void await_suspend(std::coroutine_handle<> handle)
|
||||
{
|
||||
loop_->runOnQuit([handle]() { handle.resume(); });
|
||||
}
|
||||
|
||||
private:
|
||||
trantor::EventLoop *loop_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
inline internal::TimerAwaiter sleepCoro(
|
||||
@ -723,6 +738,12 @@ inline internal::LoopAwaiter queueInLoopCoro(
|
||||
return {workLoop, std::move(taskFunc), resumeLoop};
|
||||
}
|
||||
|
||||
inline internal::EndAwaiter untilQuit(trantor::EventLoop *loop)
|
||||
{
|
||||
assert(loop);
|
||||
return {loop};
|
||||
}
|
||||
|
||||
template <typename T, typename = std::void_t<>>
|
||||
struct is_resumable : std::false_type
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user