This commit is contained in:
Denis Blank 2017-10-04 02:23:55 +02:00
parent bf1ac9daee
commit ddd5b0a0a6
2 changed files with 16 additions and 1 deletions

View File

@ -35,6 +35,11 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#if !defined(CONTINUABLE_WITH_CUSTOM_ERROR_TYPE) && \
!defined(CONTINUABLE_WITH_NO_EXCEPTIONS)
#include <exception>
#endif
#include <continuable/detail/api.hpp> #include <continuable/detail/api.hpp>
#include <continuable/detail/hints.hpp> #include <continuable/detail/hints.hpp>
#include <continuable/detail/traits.hpp> #include <continuable/detail/traits.hpp>
@ -235,8 +240,18 @@ template <typename Invoker, typename... Args>
void packed_dispatch(types::this_thread_executor_tag, Invoker&& invoker, void packed_dispatch(types::this_thread_executor_tag, Invoker&& invoker,
Args&&... args) { Args&&... args) {
!defined(CONTINUABLE_WITH_NO_EXCEPTIONS)
// Make it possible to throw exceptions from continuations chained
// through `then` or `flow`.
try {
std::forward<Invoker>(invoker)(std::forward<Args>(args)...);
} catch (...) {
std::current_exception();
}
#else
// Invoke the callback with the decorated invoker immediately // Invoke the callback with the decorated invoker immediately
std::forward<Invoker>(invoker)(std::forward<Args>(args)...); std::forward<Invoker>(invoker)(std::forward<Args>(args)...);
#endif
} }
/// Invoke the callback through the given executor /// Invoke the callback through the given executor

View File

@ -128,7 +128,7 @@ auto as_future(continuable_base<Data, Annotation>&& continuable) {
auto future = callback.get_future(); auto future = callback.get_future();
// Dispatch the continuation with the promise resolving callback // Dispatch the continuation with the promise resolving callback
std::move(continuable).then(std::move(callback)).done(); std::move(continuable).flow(std::move(callback)).done();
return future; return future;
} }