mirror of
https://github.com/oatpp/oatpp.git
synced 2024-11-21 03:14:51 +08:00
CoroutineStarter. keep(...) method to keep vars.
This commit is contained in:
parent
22dfd36e7d
commit
92b2a0debf
@ -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;
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user