mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 08:46:44 +08:00
Some ideas
This commit is contained in:
parent
d842c14268
commit
25fad02a9d
@ -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
|
// Create a worker object which when invoked calls the callback with the
|
||||||
// the returned arguments.
|
// the returned arguments.
|
||||||
auto work = [
|
auto work = [invoker = std::forward<Invoker>(invoker),
|
||||||
invoker = std::forward<Invoker>(invoker),
|
args = std::make_tuple(std::forward<Args>(args)...)]() mutable {
|
||||||
args = std::make_tuple(std::forward<Args>(args)...)
|
|
||||||
]() mutable {
|
|
||||||
traits::unpack(
|
traits::unpack(
|
||||||
[&](auto&&... captured_args) {
|
[&](auto&&... captured_args) {
|
||||||
// Just use the packed dispatch method which dispatches the work on
|
// 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> {
|
struct error_handler_base<handle_errors::no, Base> {
|
||||||
/// The operator which is called when an error occurred
|
/// The operator which is called when an error occurred
|
||||||
void operator()(exception_arg_t tag, exception_t exception) && {
|
void operator()(exception_arg_t tag, exception_t exception) && {
|
||||||
|
// TODO Add control flow info here
|
||||||
|
|
||||||
// Forward the error to the next callback
|
// Forward the error to the next callback
|
||||||
std::move(static_cast<Base*>(this)->next_callback_)(tag,
|
std::move(static_cast<Base*>(this)->next_callback_)(tag,
|
||||||
std::move(exception));
|
std::move(exception));
|
||||||
@ -606,6 +606,7 @@ struct callback_base<identity<Args...>, HandleResults, HandleErrors, Callback,
|
|||||||
Callback callback_;
|
Callback callback_;
|
||||||
Executor executor_;
|
Executor executor_;
|
||||||
NextCallback next_callback_;
|
NextCallback next_callback_;
|
||||||
|
int callstack_;
|
||||||
|
|
||||||
explicit callback_base(Callback callback, Executor executor,
|
explicit callback_base(Callback callback, Executor executor,
|
||||||
NextCallback next_callback)
|
NextCallback next_callback)
|
||||||
@ -751,6 +752,7 @@ struct chained_continuation<identity<Args...>, identity<NextArgs...>,
|
|||||||
Continuation continuation_;
|
Continuation continuation_;
|
||||||
Callback callback_;
|
Callback callback_;
|
||||||
Executor executor_;
|
Executor executor_;
|
||||||
|
int callstack_;
|
||||||
|
|
||||||
explicit chained_continuation(Continuation continuation, Callback callback,
|
explicit chained_continuation(Continuation continuation, Callback callback,
|
||||||
Executor executor)
|
Executor executor)
|
||||||
|
|||||||
@ -73,7 +73,6 @@ auto async(Callable&& callable, Executor&& executor, Args&&... args) {
|
|||||||
hint, util::ownership{});
|
hint, util::ownership{});
|
||||||
}
|
}
|
||||||
} // namespace operations
|
} // namespace operations
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace cti
|
} // namespace cti
|
||||||
|
|
||||||
|
|||||||
@ -20,10 +20,53 @@
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <vector>
|
||||||
#include <continuable/continuable.hpp>
|
#include <continuable/continuable.hpp>
|
||||||
|
|
||||||
using namespace cti;
|
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*/) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user