Skip to content

Execute NSOperationQueue mainQueue on main thread#591

Merged
rfm merged 1 commit intomasterfrom
fix-NSOperationQueue-mainQueue
Mar 28, 2026
Merged

Execute NSOperationQueue mainQueue on main thread#591
rfm merged 1 commit intomasterfrom
fix-NSOperationQueue-mainQueue

Conversation

@triplef
Copy link
Copy Markdown
Member

@triplef triplef commented Mar 19, 2026

Currently [NSOperationQueue mainQueue] is just a normal queue, meaning it executes operations on a dedicated thread. However the expectation of this API is that operations get executed on the main thread, as is done with this change.

@triplef triplef requested a review from rfm as a code owner March 19, 2026 13:38
@triplef
Copy link
Copy Markdown
Member Author

triplef commented Mar 23, 2026

When building with libdispatch, NSOperationQueue should really be backed by libdispatch queues and support the underlyingQueue property (and fix this issue by using the libdispatch main queue as underlying queue for the mainQueue property), but that’s a bigger refactor (there’s an old branch that Greg had started for this here).

Copy link
Copy Markdown
Contributor

@rfm rfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I don't think that executing in the main thread is a good or intuitive behavior (to me the main point of an operation queue is to avoid blocking the main thread), I agree that it seems to be the way OSX implements it, and it's easy to work around by creating a new queue.

@rfm rfm merged commit 6774619 into master Mar 28, 2026
10 checks passed
@triplef
Copy link
Copy Markdown
Member Author

triplef commented Mar 29, 2026

Thanks Richard. This API is usually used to make block-based APIs like this NSNotificationCenter API run the block on the main thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants