1
This commit is contained in:
parent
1607ee5487
commit
1d7e8a1087
@ -20,7 +20,7 @@ void CoMgr::Init()
|
|||||||
[i] (Coroutine* co)
|
[i] (Coroutine* co)
|
||||||
{
|
{
|
||||||
a8::XPrintf("call subco A %d %d\n", {i, a8::XGetTickCount()});
|
a8::XPrintf("call subco A %d %d\n", {i, a8::XGetTickCount()});
|
||||||
//co->CoAwait(co->Sleep(3000));
|
co->CoAwait(co->Sleep(3000));
|
||||||
}).lock());
|
}).lock());
|
||||||
a8::XPrintf("call A %d %d\n", {i, a8::XGetTickCount()});
|
a8::XPrintf("call A %d %d\n", {i, a8::XGetTickCount()});
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,16 @@ std::shared_ptr<Awaiter> Awaiter::Sleep(int time)
|
|||||||
return std::make_shared<TimerPromise>(time);
|
return std::make_shared<TimerPromise>(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Awaiter::DoDone()
|
||||||
|
{
|
||||||
|
done_ = true;
|
||||||
|
for (auto notifyer : notifyers_) {
|
||||||
|
if (!notifyer.expired()) {
|
||||||
|
notifyer.lock()->DoResume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Promise::DoAwait()
|
void Promise::DoAwait()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -136,12 +146,7 @@ void TimerPromise::DoAwait()
|
|||||||
[this, _self = shared_from_this()] (int event, const a8::Args* args) mutable
|
[this, _self = shared_from_this()] (int event, const a8::Args* args) mutable
|
||||||
{
|
{
|
||||||
if (event == a8::TIMER_EXEC_EVENT) {
|
if (event == a8::TIMER_EXEC_EVENT) {
|
||||||
done_ = true;
|
DoDone();
|
||||||
for (auto notifyer : notifyers_) {
|
|
||||||
if (!notifyer.expired()) {
|
|
||||||
notifyer.lock()->DoResume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ protected:
|
|||||||
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;
|
||||||
|
void DoDone();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<a8::Results> results_;
|
std::shared_ptr<a8::Results> results_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user