-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathbase_coroutine_system_winui.h
50 lines (43 loc) · 1.47 KB
/
base_coroutine_system_winui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
WINRT_EXPORT namespace winrt
{
[[nodiscard]] inline auto resume_foreground(
Microsoft::System::DispatcherQueue const& dispatcher,
Microsoft::System::DispatcherQueuePriority const priority = Microsoft::System::DispatcherQueuePriority::Normal) noexcept
{
struct awaitable
{
awaitable(Microsoft::System::DispatcherQueue const& dispatcher, Microsoft::System::DispatcherQueuePriority const priority) noexcept :
m_dispatcher(dispatcher),
m_priority(priority)
{
}
bool await_ready() const noexcept
{
return false;
}
bool await_resume() const noexcept
{
return m_queued;
}
bool await_suspend(impl::coroutine_handle<> handle)
{
return m_dispatcher.TryEnqueue(m_priority, [handle, this]
{
m_queued = true;
handle();
});
}
private:
Microsoft::System::DispatcherQueue const& m_dispatcher;
Microsoft::System::DispatcherQueuePriority const m_priority;
bool m_queued{};
};
return awaitable{ dispatcher, priority };
};
#ifdef WINRT_IMPL_COROUTINES
inline auto operator co_await(Microsoft::System::DispatcherQueue const& dispatcher)
{
return resume_foreground(dispatcher);
}
#endif
}