18 #if defined(LIBCOPP_MACRO_ENABLE_STD_COROUTINE) && LIBCOPP_MACRO_ENABLE_STD_COROUTINE
20 using my_generator = copp::generator_future<int>;
21 std::list<my_generator::context_pointer_type> g_sample_executor;
23 static void generator_callback(my_generator::context_pointer_type ctx) {
24 g_sample_executor.emplace_back(std::move(ctx));
27 static copp::callable_future<void> coroutine_simulator_rpc() {
28 my_generator generator_object{generator_callback};
29 auto value1 = co_await generator_object;
30 std::cout <<
"co_await named generator: " << value1 << std::endl;
31 auto value2 = co_await my_generator{generator_callback};
32 std::cout <<
"co_await temporary generator: " << value2 << std::endl;
34 generator_object.get_context()->reset_value();
35 auto value3 = co_await generator_object;
36 std::cout <<
"reset and co_await named generator again: " << value3 << std::endl;
42 auto f = coroutine_simulator_rpc();
44 while (!g_sample_executor.empty()) {
45 auto ctx = g_sample_executor.front();
46 g_sample_executor.pop_front();
47 ctx->set_value(++result);
53 puts(
"this sample require cotask enabled and compiler support c++20 coroutine");