Skip to content

Conversation

dreampiggy
Copy link
Contributor

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

This close #3765

…SDCallbackQueue and may callback in non-main queue
@dreampiggy dreampiggy force-pushed the bugfix/uiview_webcache_sdcallbackqueue branch from f9f14cf to 9db39a4 Compare November 11, 2024 09:23
…for UI-related code logic

Handled two cases in real-world app
@dreampiggy dreampiggy force-pushed the bugfix/uiview_webcache_sdcallbackqueue branch from 9db39a4 to ed1f0f8 Compare November 11, 2024 09:43
This used for user who really need `mainThread` but not `mainQueue`
@dreampiggy dreampiggy changed the title Deprecate dispatch_main_async_safe, UIView+WebCache API now supports SDCallbackQueue and may callback in non-main queue Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case Nov 14, 2024
…e `SafeAsyncMainQueue`, others revert back to default value

The implementation don't need complicated check, using object compare is enough
@dreampiggy dreampiggy force-pushed the bugfix/uiview_webcache_sdcallbackqueue branch from 64f9ffb to b4c741a Compare November 14, 2024 13:35
@dreampiggy
Copy link
Contributor Author

Some one point this that we should always use MainThread to check for dispatch. Never use MainQueue

So what's the real correct way ? Why the SDWebImage original author use dispatch_queue_main to check if it's suitable to call the completion block in sync?

@Kyle-Ye

https://twitter.com/KyleSwifter/status/1856704385285566896

@dreampiggy dreampiggy changed the title Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case, and defaults to MainThread Nov 15, 2024
@dreampiggy dreampiggy changed the title Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case, and defaults to MainThread Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread (for UIKit diffable data source) and .safeAsyncMainQueue (for most common cases) Feb 20, 2025
@dreampiggy dreampiggy added this to the 5.21.0 milestone Feb 20, 2025
@dreampiggy
Copy link
Contributor Author

TLDR

For normal image loading, we use SDCallbackPolicySafeAsyncMainQueue, which only sync when in the main queue. This is for the common case. And I don't want to break exists user's behavior

For UICollectionViewDiffableDataSource, use SDCallbackPolicySafeAsyncMainThread, which don't care about GCD queue but only check main thread.

@dreampiggy dreampiggy merged commit c085d53 into SDWebImage:master Feb 20, 2025
5 of 7 checks passed
@dreampiggy dreampiggy added the view category Related to UIView Category label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
view category Related to UIView Category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dispatch_main_async_safe issue
1 participant