Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
async_main.h
Go to the documentation of this file.
1#pragma once
7#include <asyncpp/fire_and_forget.h>
8#include <asyncpp/simple_dispatcher.h>
9#include <asyncpp/task.h>
10
11asyncpp::task<int> async_main(int argc, const char** argv);
12//NOLINTNEXTLINE(misc-definitions-in-headers)
13int main(int argc, const char** argv) {
14 using asyncpp::eager_fire_and_forget_task;
16 simple_dispatcher disp;
17 std::pair<int, std::exception_ptr> result{-1, nullptr};
18 disp.push([&]() {
19 [](simple_dispatcher* disp, std::pair<int, std::exception_ptr>& result, int argc,
20 const char** argv) -> eager_fire_and_forget_task<> {
21 try {
22 result.first = co_await async_main(argc, argv);
23 } catch (...) {
24 result.second = std::current_exception();
25 result.first = -1;
26 }
27 disp->stop();
28 }(&disp, result, argc, argv);
29 });
30 disp.run();
31 if (result.second) std::rethrow_exception(result.second);
32 return result.first;
33}
A very basic dispatcher that runs in a single thread until manually stopped.
Definition simple_dispatcher.h:14
void push(std::function< void()> cbfn) override
Push a function to be executed on the dispatcher.
Definition simple_dispatcher.h:25
Generic task type.
Definition task.h:88