Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refined C++20 couroutune example. #105

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions example/ep_cpp20coro_mqtt_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ namespace as = boost::asio;
namespace am = async_mqtt;

as::awaitable<void>
proc(std::string_view host, std::string_view port) {
proc(
auto& amep,
std::string_view host,
std::string_view port) {
auto exe = co_await as::this_coro::executor;
as::ip::tcp::socket resolve_sock{exe};
as::ip::tcp::resolver res{exe};
auto amep = am::endpoint<am::role::client, am::protocol::mqtt>::create(
am::protocol_version::v3_1_1,
exe
);
std::cout << "start" << std::endl;

try {
Expand Down Expand Up @@ -183,6 +182,10 @@ int main(int argc, char* argv[]) {
return -1;
}
as::io_context ioc;
as::co_spawn(ioc.get_executor(), proc(argv[1], argv[2]), as::detached);
auto amep = am::endpoint<am::role::client, am::protocol::mqtt>::create(
am::protocol_version::v3_1_1,
ioc.get_executor()
);
as::co_spawn(amep->strand(), proc(amep, argv[1], argv[2]), as::detached);
ioc.run();
}