diff --git a/server/robotserver/coroutine.cc b/server/robotserver/coroutine.cc index cabfef4c..dab8b336 100644 --- a/server/robotserver/coroutine.cc +++ b/server/robotserver/coroutine.cc @@ -83,15 +83,7 @@ void Coroutine::CoYield() std::shared_ptr Coroutine::CoAwait(std::shared_ptr awaiter) { CoSuspend(); - #if 0 - awaiter->Await - ( - [] () - { - - }); - #endif - CoYield(); + awaiter->DoAwait(); while (!awaiter->Done()) { CoYield(); } @@ -137,10 +129,11 @@ void TimerPromise::DoAwait() f8::Timer::Instance()->SetTimeout ( time_, - [self] (int event, const a8::Args* args) mutable + [this, self] (int event, const a8::Args* args) mutable { if (event == a8::TIMER_EXEC_EVENT) { - for (auto notifyer : self->notifyers_) { + done_ = true; + for (auto notifyer : notifyers_) { if (!notifyer.expired()) { notifyer.lock()->DoResume(); } diff --git a/server/robotserver/coroutine.h b/server/robotserver/coroutine.h index dadd1c17..adc431d6 100644 --- a/server/robotserver/coroutine.h +++ b/server/robotserver/coroutine.h @@ -36,12 +36,13 @@ class Awaiter : public std::enable_shared_from_this std::shared_ptr Sleep(int time); protected: + bool done_ = false; + std::list> notifyers_; void Await(std::shared_ptr notifyer); virtual void DoAwait() = 0; private: - bool done_ = false; std::shared_ptr results_; std::function cb_; friend class Coroutine;