1
This commit is contained in:
parent
3d6b01a527
commit
fd1386e1be
@ -64,9 +64,17 @@ std::shared_ptr<a8::Results> Coroutine::CoAwait(Awaiter& awaiter)
|
|||||||
std::shared_ptr<a8::Results> Coroutine::CoAwait(Awaiter* awaiter)
|
std::shared_ptr<a8::Results> Coroutine::CoAwait(Awaiter* awaiter)
|
||||||
{
|
{
|
||||||
CoSuspend();
|
CoSuspend();
|
||||||
|
awaiter->Await
|
||||||
|
(
|
||||||
|
[] ()
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
CoYield();
|
||||||
while (!awaiter->Done()) {
|
while (!awaiter->Done()) {
|
||||||
CoYield();
|
CoYield();
|
||||||
}
|
}
|
||||||
|
CoResume();
|
||||||
return awaiter->GetResult();
|
return awaiter->GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,3 +99,8 @@ void Coroutine::CallExit(boost::coroutines2::coroutine<void>::push_type& sink)
|
|||||||
{
|
{
|
||||||
sink_ = nullptr;
|
sink_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Coroutine::Await(std::function<void()> cb)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -32,10 +32,18 @@ class Awaiter
|
|||||||
return done_;
|
return done_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void Await(std::function<void()> cb)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool done_ = false;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Promise : public Awaiter
|
class Promise : public Awaiter
|
||||||
@ -63,6 +71,8 @@ class Coroutine : public Awaiter, public std::enable_shared_from_this<Coroutine>
|
|||||||
void CallEnter(boost::coroutines2::coroutine<void>::push_type& sink);
|
void CallEnter(boost::coroutines2::coroutine<void>::push_type& sink);
|
||||||
void CallExit(boost::coroutines2::coroutine<void>::push_type& sink);
|
void CallExit(boost::coroutines2::coroutine<void>::push_type& sink);
|
||||||
|
|
||||||
|
virtual void Await(std::function<void()> cb) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
list_head co_entry_;
|
list_head co_entry_;
|
||||||
list_head exec_entry_;
|
list_head exec_entry_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user