Skip to content
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

Conversation

aaronr93
Copy link
Contributor

@aaronr93 aaronr93 commented Jan 1, 2018

When there are no additions to the collection, numberOfAdditionsCompletion (and therefore completeBatchFetching) 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.

…round thread when no items are added to the collection
@CLAassistant
Copy link

CLAassistant commented Jan 1, 2018

CLA assistant check
All committers have signed the CLA.

maicki
maicki previously requested changes Jan 2, 2018
Copy link
Contributor

@maicki maicki left a 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"))
Copy link
Contributor

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"))
}
Copy link
Contributor

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.

@appleguy
Copy link
Member

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?

@aaronr93
Copy link
Contributor Author

@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.

Copy link
Member

@Adlai-Holler Adlai-Holler left a 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.

@Adlai-Holler Adlai-Holler merged commit d697198 into TextureGroup:master Jan 31, 2018
@aaronr93 aaronr93 deleted the Examples_ASDKgram-Swift_FixMainThreadMinorIssue branch February 2, 2018 04:45
bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
…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
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.

None yet

5 participants