Some ideas

This commit is contained in:
Denis Blank 2019-04-04 07:04:12 +02:00
parent d842c14268
commit 25fad02a9d
3 changed files with 51 additions and 7 deletions

View File

@ -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>(invoker),
args = std::make_tuple(std::forward<Args>(args)...)
]() mutable {
auto work = [invoker = std::forward<Invoker>(invoker),
args = std::make_tuple(std::forward<Args>(args)...)]() mutable {
traits::unpack(
[&](auto&&... captured_args) {
// Just use the packed dispatch method which dispatches the work on
@ -557,6 +555,8 @@ template <typename Base>
struct error_handler_base<handle_errors::no, 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<Base*>(this)->next_callback_)(tag,
std::move(exception));
@ -606,6 +606,7 @@ struct callback_base<identity<Args...>, 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<Args...>, identity<NextArgs...>,
Continuation continuation_;
Callback callback_;
Executor executor_;
int callstack_;
explicit chained_continuation(Continuation continuation, Callback callback,
Executor executor)

View File

@ -73,7 +73,6 @@ auto async(Callable&& callable, Executor&& executor, Args&&... args) {
hint, util::ownership{});
}
} // namespace operations
} // namespace detail
} // namespace cti

View File

@ -20,10 +20,53 @@
SOFTWARE.
**/
#include <exception>
#include <vector>
#include <continuable/continuable.hpp>
using namespace cti;
int main(int, char**) {
// ...
continuable<std::string> http_request(std::string /*url*/) {
return async([]() -> std::string {
throw std::exception{}; //
});
}
struct ResultSet {};
struct Buffer {};
continuable<ResultSet> mysql_query(std::string /*url*/) {
return make_ready_continuable(ResultSet{});
}
continuable<Buffer> 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<void const*>;
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*/) {
// ...
});
}