std::futurefuture_obj = std::async(std::launch::async, [](){ return 42; }); int result = future_obj.get(); // blocks until result is available std::cout << result << std::endl;
std::futureIn this example, the `co_await` keyword is used to suspend the execution of the function until the `future` object is complete. Once the `future` object completes, the result is assigned to the `result` variable and printed to the console. Package/library: This code example uses the C++20 coroutines library.future_obj = std::async(std::launch::async, [](){ return 42; }); int result = co_await future_obj; // waits for result to be available std::cout << result << std::endl;