Created
May 4, 2018 00:20
-
-
Save kennykerr/a604a96839296fe05b23a1bbf1b2f440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "winrt/base.h" | |
#include <Windows.h> | |
using namespace winrt; | |
using namespace Windows::Foundation; | |
using namespace std::chrono; | |
template <typename...Async> | |
void wait_for_any(Async&&... async) | |
{ | |
auto signal = std::make_shared<handle>(CreateEvent(nullptr, true, false, nullptr)); | |
(async.Completed([signal](auto&&...) | |
{ | |
SetEvent(signal->get()); | |
}), ...); | |
WaitForSingleObject(signal->get(), INFINITE); | |
} | |
IAsyncAction A() { co_await 3s; puts("A"); } | |
IAsyncAction B() { co_await 2s; puts("B"); } | |
IAsyncAction C() { co_await 1s; puts("C"); } | |
int main() | |
{ | |
init_apartment(); | |
wait_for_any(A(), B(), C()); | |
puts("At least one completed"); | |
getchar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment