diff --git a/server/robotserver/comgr.cc b/server/robotserver/comgr.cc index 9278ffb9..30a140a5 100644 --- a/server/robotserver/comgr.cc +++ b/server/robotserver/comgr.cc @@ -20,7 +20,7 @@ void CoMgr::Init() [i] (Coroutine* co) { a8::XPrintf("call subco A %d %d\n", {i, a8::XGetTickCount()}); - //co->CoAwait(co->Sleep(3000)); + co->CoAwait(co->Sleep(3000)); }).lock()); a8::XPrintf("call A %d %d\n", {i, a8::XGetTickCount()}); } diff --git a/server/robotserver/coroutine.cc b/server/robotserver/coroutine.cc index 784114fe..f5f0ed33 100644 --- a/server/robotserver/coroutine.cc +++ b/server/robotserver/coroutine.cc @@ -19,6 +19,16 @@ std::shared_ptr Awaiter::Sleep(int time) return std::make_shared(time); } +void Awaiter::DoDone() +{ + done_ = true; + for (auto notifyer : notifyers_) { + if (!notifyer.expired()) { + notifyer.lock()->DoResume(); + } + } +} + void Promise::DoAwait() { @@ -136,12 +146,7 @@ void TimerPromise::DoAwait() [this, _self = shared_from_this()] (int event, const a8::Args* args) mutable { if (event == a8::TIMER_EXEC_EVENT) { - done_ = true; - for (auto notifyer : notifyers_) { - if (!notifyer.expired()) { - notifyer.lock()->DoResume(); - } - } + DoDone(); } }); } diff --git a/server/robotserver/coroutine.h b/server/robotserver/coroutine.h index 4d9ba029..46986d87 100644 --- a/server/robotserver/coroutine.h +++ b/server/robotserver/coroutine.h @@ -42,6 +42,7 @@ protected: std::list> notifyers_; void Await(std::shared_ptr notifyer); virtual void DoAwait() = 0; + void DoDone(); private: std::shared_ptr results_;