-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you run final cleanup with a chain? #58
Comments
@geiseri Could you maybe provide a code example what you have tried so far? |
This is the original code: My issue is that this chain resolves at a future time and I need promise::Promise getResponse(Type symbolType, std::string symbol) {
auto inst = registry.get(symbolType); // This is a shared ptr
return inst->resolveScore(symbol).finally([inst ]() {(void)inst;});
} I got this far, but it crashes with cti::continuable<StrategyResponse> getResponse(Type symbolType, std::string symbol) {
auto inst = registry.get(symbolType); // This is a shared ptr
return inst->resolveScore(symbol)
.then([inst](StrategyResponse res) {
(void)inst;
return cti::make_ready_continuable(res);
});
} If I pull the Does that make more sense? |
could it be that you're allowing the |
It is when I am still in a |
Not quite sure what you mean by this. It might be helpful to include more context to how you’re calling this function, and how you’re handling the lifetime of the continuable that it returns. There’s nothing wrong with the code you’ve shown here, so the error must be elsewhere. Maybe put a breakpoint in your ‘inst’ object’s destructor and look at the stack trace. A couple of other things:
|
I second what @Spongman says. Tracing the destructor of your shared_ptr object through a debugger is probably your best option. Additionally I have to add that the callable that you pass to So if you require your handle/shared_ptr to stay alive afterwards you need to reference it in the handler you are using the handle in. Btw. you can also use |
Okay, I think I found the issue. Originally the code used |
There is no mechanism to allow a true finally handler that runs when the entire chain has ended because in the process of building the chain you might always add further continuations. The executor is getting passed down into the continuation and therefore is not accessible anymore from outside. |
@Naios
I am currently using https://github.com/xhawk18/promise-cpp and would like to move to continuable since I am using native asio. One thing that is holding me back is the
Promise::finally(FUNC_ON_FINALLY on_finally)
method. I use this because I need to have a few cleanup operations that can only run after the entire chain has been resolved. I was having issues finding a way to make this withnext(...)
without duplicating code in both functions. Am I missing something?The text was updated successfully, but these errors were encountered: