Skip to content

Conversation

dreampiggy
Copy link
Contributor

This is the best practice for UI related code

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: ...

Pull Request Description

After discussion in #3766

Actually this SafeAsyncMainQueue does not do anything useful. UIKit always check MainThread , but not MainQueue. So, we should remove this policy and always use SafeAsyncMainThread instead

This is also what Kingfisher or ReactNative do in their latest release, to support UICollectionViewDiffableDataSource

…t need main queue check at all

This is the best practice for UI related code
@dreampiggy dreampiggy added this to the 5.21.0 milestone Feb 21, 2025
@dreampiggy dreampiggy merged commit c184125 into SDWebImage:master Feb 22, 2025
6 of 7 checks passed
@dreampiggy dreampiggy deleted the feature/remove_asyncMainQueue branch February 22, 2025 08:50
@@ -17,18 +17,16 @@ typedef NS_ENUM(NSUInteger, SDCallbackPolicy) {
SDCallbackPolicyDispatch = 1,
/// Ignore any async/sync and just directly invoke `block` in current queue (without `dispatch_async`/`dispatch_sync`)
SDCallbackPolicyInvoke = 2,
/// Ensure callback in main queue (no gurantee on main thread). Do `dispatch_async` if the current queue is not main queue; else do invoke `block`. Never use `dispatch_sync`, suitable for general UI-related code
SDCallbackPolicySafeAsyncMainQueue = 3,
/// Ensure callback in main thread. Do `dispatch_async` if the `NSThread.isMainTrhead == true` ; else do invoke `block`. Never use `dispatch_sync`, suitable for special UI-related code
Copy link
Contributor Author

@dreampiggy dreampiggy Feb 24, 2025

Choose a reason for hiding this comment

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

Seems the comment is not correct. The code implementation shows “When current thread is not main thread, do dispatch_async”

TODO: fix later @dreampiggy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant