1
This commit is contained in:
parent
c85563a289
commit
8683150ce8
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user