-
Notifications
You must be signed in to change notification settings - Fork 68
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
future<T>.always([]{}); #266
Comments
I would consider at this point, that your tasks do not throw. |
My tasks certainly do throw but there are instances where regardless of if a task succeeds or not I want some code to execute. This could be useful in many cases but the main one I use it for is state tracking via a construct like RAII. Like when a task finishes do this even if you failed. I am curious however what the new interface will ultimately turn out to be. I have been following your progress on error and exception. |
Two questions:
|
I'm not certain I want to promote the idea of depending on side-effects with future continuations. But I believe (except for the member function syntax) this is easily expressible as: // arguments are future, executor, task.
template <class T, class E, class F>
auto always(future<T>&& x, E&& e, F&& f) {
return future<T> move(x).recover(std::forward<E>(e), [_f = std::forward<F>(f)](auto&& f) {
std::move(_f)();
return std::forward<F>(f); // is this forward redundant?
});
} |
I think it would be nice to have a way to easily request that a continuation in a chain be done every time regardless of error state. I am accomplishing this now with
f.recover([](auto f){});
but I thinkf.always([]{});
is more expressive.The text was updated successfully, but these errors were encountered: