【发布时间】:2020-07-28 12:20:21
【问题描述】:
观看 c++ 讲座 (https://youtu.be/DLLt4anKXKU?t=1589),我试图了解未来如何使用 co_await;示例:
auto compute = []() -> std::future<int> {
int fst = co_await std::async(get_first);
int snd = co_await std::async(get_second);
co_return fst + snd;
};
auto f = compute();
/* some heavy task */
f.get();
我不明白co_await std::async(get_first) 如何以及何时将控制权交还给compute。即std::future 如何实现一个等待接口(类型)。
【问题讨论】:
标签: c++ future coroutine c++20