This commit is contained in:
aozhiwei 2023-05-27 14:08:27 +08:00
parent c85563a289
commit 8683150ce8
2 changed files with 6 additions and 12 deletions

View File

@ -83,15 +83,7 @@ void Coroutine::CoYield()
std::shared_ptr<a8::Results> Coroutine::CoAwait(std::shared_ptr<Awaiter> awaiter) std::shared_ptr<a8::Results> Coroutine::CoAwait(std::shared_ptr<Awaiter> awaiter)
{ {
CoSuspend(); CoSuspend();
#if 0 awaiter->DoAwait();
awaiter->Await
(
[] ()
{
});
#endif
CoYield();
while (!awaiter->Done()) { while (!awaiter->Done()) {
CoYield(); CoYield();
} }
@ -137,10 +129,11 @@ void TimerPromise::DoAwait()
f8::Timer::Instance()->SetTimeout f8::Timer::Instance()->SetTimeout
( (
time_, time_,
[self] (int event, const a8::Args* args) mutable [this, self] (int event, const a8::Args* args) mutable
{ {
if (event == a8::TIMER_EXEC_EVENT) { if (event == a8::TIMER_EXEC_EVENT) {
for (auto notifyer : self->notifyers_) { done_ = true;
for (auto notifyer : notifyers_) {
if (!notifyer.expired()) { if (!notifyer.expired()) {
notifyer.lock()->DoResume(); notifyer.lock()->DoResume();
} }

View File

@ -36,12 +36,13 @@ class Awaiter : public std::enable_shared_from_this<Awaiter>
std::shared_ptr<Awaiter> Sleep(int time); std::shared_ptr<Awaiter> Sleep(int time);
protected: protected:
bool done_ = false;
std::list<std::weak_ptr<Awaiter>> notifyers_; std::list<std::weak_ptr<Awaiter>> notifyers_;
void Await(std::shared_ptr<Awaiter> notifyer); void Await(std::shared_ptr<Awaiter> notifyer);
virtual void DoAwait() = 0; virtual void DoAwait() = 0;
private: private:
bool done_ = false;
std::shared_ptr<a8::Results> results_; std::shared_ptr<a8::Results> results_;
std::function<void()> cb_; std::function<void()> cb_;
friend class Coroutine; friend class Coroutine;