// Copyright (c) 2023 Klemens D. Morgenstern // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include using namespace boost; struct Result { std::string value; }; struct Task { std::string value; }; async::generator client(Task t) { for (int i = 0; ; ++i < 100) { std::cout << "processing: " << t.value << std::endl; t = co_yield Result{ std::format("result-{}-{}", i, t.value) }; } co_return Result{ std::format("result-{}-{}", 100, t.value) }; } async::main co_main(int argc, char* argv[]) { try { auto c = client(Task{ std::string{"tx"} }); for (int i = 0; i < 10; ++i) { Task t{ std::format("t{}", i) }; std::cout << (co_await c(t)).value << std::endl; } } catch (std::exception const& e) { std::cerr << "ERR: " << e.what() << std::endl; } co_return 0; }