-
Notifications
You must be signed in to change notification settings - Fork 247
/
base_coroutine_ui_core.h
48 lines (40 loc) · 1.36 KB
/
base_coroutine_ui_core.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
WINRT_EXPORT namespace winrt
{
[[nodiscard]] inline auto resume_foreground(
Windows::UI::Core::CoreDispatcher const& dispatcher,
Windows::UI::Core::CoreDispatcherPriority const priority = Windows::UI::Core::CoreDispatcherPriority::Normal) noexcept
{
struct awaitable
{
awaitable(Windows::UI::Core::CoreDispatcher const& dispatcher, Windows::UI::Core::CoreDispatcherPriority const priority) noexcept :
m_dispatcher(dispatcher),
m_priority(priority)
{
}
bool await_ready() const noexcept
{
return false;
}
void await_resume() const noexcept
{
}
void await_suspend(impl::coroutine_handle<> handle) const
{
m_dispatcher.RunAsync(m_priority, [handle]
{
handle();
});
}
private:
Windows::UI::Core::CoreDispatcher const& m_dispatcher;
Windows::UI::Core::CoreDispatcherPriority const m_priority;
};
return awaitable{ dispatcher, priority };
};
#ifdef WINRT_IMPL_COROUTINES
inline auto operator co_await(Windows::UI::Core::CoreDispatcher const& dispatcher)
{
return resume_foreground(dispatcher);
}
#endif
}