-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(std::experimental::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 __cpp_coroutines | ||
inline auto operator co_await(Microsoft::System::DispatcherQueue const& dispatcher) | ||
{ | ||
return resume_foreground(dispatcher); | ||
} | ||
#endif | ||
} |