对于可等待对象(或只是) ,是否有与Promise.all
C++ 或 C++/WinRT 中的JavaScript 等效Windows.Foundation.IAsyncAction
?
例如,我正在尝试收集多个 IAsyncAction 并在它们全部完成后继续。现在我开始每个动作,然后在一个简单的循环中一个接一个地等待它们:
winrt::IAsyncAction AwaitMultiple(std::vector<winrt::IAsyncAction> actions)
{
for (const auto& action : actions)
{
co_await action;
}
}
// ... somewhere else...
winrt::IAsyncAction MyFunctionAsync()
{
std::vector<winrt::IAsyncAction> actions{};
actions.push_back(/* some function that generates an IAsyncAction */);
actions.push_back(/* some function that generates an IAsyncAction */);
actions.push_back(/* some function that generates an IAsyncAction */);
// ... etc...
co_await AwaitMultiple(actions);
// ... do other stuff...
}
有一个更好的方法吗?有语言方式吗?