From 9bf0224ca4390dd25153f64811a1a28387ecc9d0 Mon Sep 17 00:00:00 2001 From: etorth Date: Sat, 18 Jan 2025 17:28:21 +0800 Subject: [PATCH] f --- common/src/corof.hpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/common/src/corof.hpp b/common/src/corof.hpp index 69589d32..b308cd8c 100644 --- a/common/src/corof.hpp +++ b/common/src/corof.hpp @@ -222,6 +222,7 @@ namespace corof { private: std::optional m_var; + corof::eval_poller m_poller; public: template void assign(U && u) @@ -231,7 +232,9 @@ namespace corof } public: - async_variable() = default; + async_variable() + : m_poller(create_poller()) + {} public: template async_variable (const async_variable &) = delete; @@ -240,13 +243,16 @@ namespace corof public: auto operator co_await() noexcept { - return [](corof::async_variable *p) -> corof::eval_poller - { - while(!p->m_var.has_value()){ - co_await std::suspend_always{}; - } - co_return p->m_var.value(); - }(this).operator co_await(); + return m_poller.operator co_await(); + } + + private: + corof::eval_poller create_poller() + { + while(!m_var.has_value()){ + co_await std::suspend_always{}; + } + co_return m_var.value(); } };