CoroutineStarter. keep(...) method to keep vars.

This commit is contained in:
lganzzzo 2020-03-30 02:33:18 +03:00
parent 22dfd36e7d
commit 92b2a0debf
2 changed files with 32 additions and 2 deletions

View File

@ -249,8 +249,6 @@ Action CoroutineHandle::takeAction(Action&& action) {
}
case Action::TYPE_FINISH: {
/* Please note that savedCP->m_parentReturnAction should not be "REPEAT nor WAIT_RETRY" */
/* as funtion pointer (FP) is invalidated */
action = std::move(_CP->m_parentReturnAction);
AbstractCoroutine* savedCP = _CP;
_FP = _CP->m_parentReturnFP;

View File

@ -389,6 +389,16 @@ public:
*/
CoroutineStarter& next(CoroutineStarter&& starter);
/**
* Keep variables for the time coroutine pipeline is executed. <br>
* Example usage is to keep shared_ptr to an object which calls coroutine.
* @tparam Args
* @param vars
* @return - this starter.
*/
template<typename ... Args>
CoroutineStarter& keep(const Args&... vars);
};
/**
@ -631,6 +641,28 @@ public:
};
template<typename ... Args>
CoroutineStarter& CoroutineStarter::keep(const Args&... vars) {
class KeeperCoroutine : public Coroutine<KeeperCoroutine> {
private:
std::tuple<Args...> m_vars;
public:
KeeperCoroutine(const Args&... vars)
: m_vars(std::make_tuple(vars...))
{}
Action act() override {
return this->finish();
}
};
return next(KeeperCoroutine::start(vars...));
}
/**
* Abstract coroutine with result.
*/