【发布时间】:2017-09-13 07:35:28
【问题描述】:
我正试图围绕 C++ 协程特性展开思考。我阅读了 Kenny 的文章 (C++ - Introducing C++/WinRT) 并尝试观看此演示文稿,CppCon 2016: James McNellis “Introduction to C++ Coroutines"。我一直看到没有某种形式的 return 语句的非 void “函数”。例如,请参阅 Kenny 文章中的以下代码示例。 PrintFeedAsync 函数/协程具有 IAsyncAction 返回类型,但定义中没有返回语句。有人能解释一下这是如何工作的吗?
IAsyncAction PrintFeedAsync()
{
Uri uri(L"http://kennykerr.ca/feed");
SyndicationClient client;
SyndicationFeed feed = co_await client.RetrieveFeedAsync(uri);
for (SyndicationItem item : feed.Items())
{
hstring title = item.Title().Text();
printf("%ls\n", title.c_str());
}
}
int main()
{
initialize();
PrintFeedAsync().get();
}
【问题讨论】:
-
co_await调用导致函数隐式返回IAsyncAction。
标签: visual-c++ windows-runtime c++-winrt c++-coroutine