diff --git a/server/robotserver/coroutine.cc b/server/robotserver/coroutine.cc index fc405f42..d9bc59c2 100644 --- a/server/robotserver/coroutine.cc +++ b/server/robotserver/coroutine.cc @@ -2,8 +2,11 @@ #include +#include + #include "coroutine.h" #include "comgr.h" +#include "app.h" void Awaiter::Await(std::shared_ptr notifyer) { @@ -122,3 +125,17 @@ void Coroutine::DoResume() { CoResume(); } + +void TimerPromise::DoAwait() +{ + std::shared_ptr self = std::static_pointer_cast(Awaiter::shared_from_this()); + f8::Timer::Instance()->SetTimeout + ( + time_, + [self] (int event, const a8::Args* args) mutable + { + if (event == a8::TIMER_EXEC_EVENT) { + + } + }); +} diff --git a/server/robotserver/coroutine.h b/server/robotserver/coroutine.h index 6455199a..6cc9dc2e 100644 --- a/server/robotserver/coroutine.h +++ b/server/robotserver/coroutine.h @@ -45,7 +45,7 @@ protected: friend class Coroutine; }; -class Promise : public Awaiter +class Promise : public Awaiter, public std::enable_shared_from_this { protected: @@ -53,6 +53,21 @@ protected: }; +class TimerPromise : public Promise, public std::enable_shared_from_this +{ + public: + + TimerPromise(long long time) { time_ = time; }; + +protected: + + virtual void DoAwait() override; + + private: + long long time_ = 0; + +}; + class Coroutine : public Awaiter { public: