-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dealloc completion blocks on the context they're scheduled on #38
Comments
After looking into this, I don't think this is actually doable after all. There's two reasons:
If we cared enough, issue 2 could be dealt with, but issue 1 is a pretty big showstopper. I'm not inclined to be dispatching blocks onto the main queue purely to allow a block to dealloc there unless there's a very good reason to do so. |
Thinking about it some more, it's not just wasted work to send these blocks to the queue, but also if this is generalized for all contexts and not just the main context then it can produce seriously bad performance issues when low-priority queues are involved, e.g. somePromise.catch(on: .background, {
…
}).then(on: .main, {
…
}) In this scenario, a successful promise would still bounce through the Restricting it to just the main context solves this for the most part, unless the main thread is busy with work and we want to run a followup on a background queue. For example: somePromise.then(on: .main, {
…
}).catch(on: .userInitiated, {
…
}) If the main queue is backed up, our catch block will be delayed unnecessarily. |
I think I'm going to go ahead with this with the restriction that we only make this guarantee if the block actually executes (or would have executed if any relevant token wasn't invalidated). This means if you need this behavior, use We don't just guarantee this for those methods because e.g. a |
We should at least do this for
.main
, if not other contexts.PMHTTP does something similar for its completion blocks. It uses code like
The text was updated successfully, but these errors were encountered: