Add blocking dispatch_thread_events function #306
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had problems with the
dispatch_thread_events_with_callback
function either letting me have a responsive UI with high CPU usage or having to add a sleep of some sort into my callback (which made the window not work properly with focus).This PR adds a
dispatch_thread_events_blocking_with_callback
function that mirrors thedispatch_thread_events
function in that it blocks for new messages, but it adds a callback after each message is handled. This results in low CPU usage.My use case:
I have a program that runs a local
Future
s executor in the main thread, but I don't want to block the UI. I was previously using the dispatch_thread_events_with_callback function, but it resulted in high CPU usage until I added a WaitMessage to the end of my callback. However, when I added that, it would then not work properly when trying to bring the window into focus.