diff --git a/include/continuable/detail/core/base.hpp b/include/continuable/detail/core/base.hpp index 96313c9..13a959c 100644 --- a/include/continuable/detail/core/base.hpp +++ b/include/continuable/detail/core/base.hpp @@ -486,10 +486,8 @@ void on_executor(Executor&& executor, Invoker&& invoker, Args&&... args) { // Create a worker object which when invoked calls the callback with the // the returned arguments. - auto work = [ - invoker = std::forward(invoker), - args = std::make_tuple(std::forward(args)...) - ]() mutable { + auto work = [invoker = std::forward(invoker), + args = std::make_tuple(std::forward(args)...)]() mutable { traits::unpack( [&](auto&&... captured_args) { // Just use the packed dispatch method which dispatches the work on @@ -557,6 +555,8 @@ template struct error_handler_base { /// The operator which is called when an error occurred void operator()(exception_arg_t tag, exception_t exception) && { + // TODO Add control flow info here + // Forward the error to the next callback std::move(static_cast(this)->next_callback_)(tag, std::move(exception)); @@ -606,6 +606,7 @@ struct callback_base, HandleResults, HandleErrors, Callback, Callback callback_; Executor executor_; NextCallback next_callback_; + int callstack_; explicit callback_base(Callback callback, Executor executor, NextCallback next_callback) @@ -751,6 +752,7 @@ struct chained_continuation, identity, Continuation continuation_; Callback callback_; Executor executor_; + int callstack_; explicit chained_continuation(Continuation continuation, Callback callback, Executor executor) diff --git a/include/continuable/detail/operations/async.hpp b/include/continuable/detail/operations/async.hpp index 79841b6..2e0d994 100644 --- a/include/continuable/detail/operations/async.hpp +++ b/include/continuable/detail/operations/async.hpp @@ -73,7 +73,6 @@ auto async(Callable&& callable, Executor&& executor, Args&&... args) { hint, util::ownership{}); } } // namespace operations - } // namespace detail } // namespace cti diff --git a/test/playground/test-playground.cpp b/test/playground/test-playground.cpp index 0c5e288..24c240f 100644 --- a/test/playground/test-playground.cpp +++ b/test/playground/test-playground.cpp @@ -20,10 +20,53 @@ SOFTWARE. **/ +#include +#include #include using namespace cti; -int main(int, char**) { - // ... +continuable http_request(std::string /*url*/) { + return async([]() -> std::string { + throw std::exception{}; // + }); +} + +struct ResultSet {}; +struct Buffer {}; + +continuable mysql_query(std::string /*url*/) { + return make_ready_continuable(ResultSet{}); +} + +continuable read_file(std::string /*url*/) { + return make_ready_continuable(Buffer{}); +} + +struct exception_trait {}; + +struct unhandled_exception_trait {}; + +struct stacktrace_trait { + using stacktrace_type = std::vector; + + static stacktrace_type gather(std::size_t offset) noexcept { + return {}; + } + + static exception_t annotate(stacktrace_type stacktrace, + exception_t&& exception) noexcept { + return exception; + } +}; + +int main(int, char**) { + when_all(http_request("github.com"), http_request("atom.io")) + .then([](std::string /*github*/, std::string /*atom*/) { + // ... + return mysql_query("select * from `users`"); + }) + .then([](ResultSet /*result*/) { + // ... + }); }