co_await a C++/WinRT event

208 Views Asked by At

I would like to co_await the file completed event from the WinRT AudioGraph API.

Is this possible? It seams like a far superior way to program than using state or recursion.

1

There are 1 best solutions below

0
Tom Huntington On BEST ANSWER

Yes. You co_await the resume_on_signal function.

co_await winrt::resume_on_signal(m_event_handle);

Here's the handle being created

HANDLE m_event_handle;
m_event_handle  = CreateEventA(nullptr, false, false, nullptr);

Then subscribe to the event with the following event handler

fileInputNode.FileCompleted([this](auto, auto) { winrt::check_bool(SetEvent(m_event_handle)); });