-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixed: completeBatchFetching is called on a background thread #731
Fixed: completeBatchFetching is called on a background thread #731
Conversation
…round thread when no items are added to the collection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronr93 Thanks for working on it! After making the changes let me know and we will get it in. Thanks!
@@ -67,7 +67,9 @@ final class PhotoFeedModel { | |||
private func fetchNextPageOfPopularPhotos(replaceData: Bool, numberOfAdditionsCompletion: @escaping (Int, NetworkingErrors?) -> ()) { | |||
|
|||
if currentPage == totalPages, currentPage != 0 { | |||
return numberOfAdditionsCompletion(0, .customError("No pages left to parse")) | |||
DispatchQueue.main.async { | |||
return numberOfAdditionsCompletion(0, .customError("No pages left to parse")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the "return" here.
return numberOfAdditionsCompletion(0, .customError("No pages left to parse")) | ||
DispatchQueue.main.async { | ||
return numberOfAdditionsCompletion(0, .customError("No pages left to parse")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a "return" here otherwise it would execute this path although it should return like it did before.
Does this bug also exist in the Objective-C version? Also, are all the ASBatch calls on ASCollectionNode behaving correctly, and only communicating with the delegate on main? |
@maicki I made those changes. Sorry about the delay; I need to tweak my Github notifications. I found the same issue in the Objective-C version (95% sure...I'm not very experienced with Objective-C) and fixed it. @appleguy I'm not sure if all the examples are correctly communicating with the delegate, if that's what you mean. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable. Thanks! Note @appleguy the collectionNode:willBeginBatchFetchWithContext:
is documented to be called off-main. Although it would make a lot of sense to have specified it to be main thread and warn the user not to do too much.
Fix header
…eGroup#731) * Fixed breaking issue where completeBatchFetching is called on a background thread when no items are added to the collection * Changed spaces to tabs for consistency * Moved return statement for Code Review feedback * Fixed the same issue in the Objective-C version of ASDKgram * One more * Update PhotoFeedModel.m Fix header
When there are no additions to the collection,
numberOfAdditionsCompletion
(and thereforecompleteBatchFetching
) is called on a background thread instead of the main thread.This issue has not come up in this example because the user would have to scroll literally 1000 pages in order to experience it. This is important to fix to maintain consistency in the examples.