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)
{
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();
}

View File

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