architecture-components-samples icon indicating copy to clipboard operation
architecture-components-samples copied to clipboard

Update NetworkBoundResource.kt

Open xiaobailong24 opened this issue 6 years ago • 9 comments

remove unnecessary switch to main thread

xiaobailong24 avatar Feb 22 '19 03:02 xiaobailong24

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

googlebot avatar Feb 22 '19 03:02 googlebot

I signed it!

xiaobailong24 avatar Feb 22 '19 03:02 xiaobailong24

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

googlebot avatar Feb 22 '19 03:02 googlebot

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

googlebot avatar Feb 22 '19 03:02 googlebot

I also found switching main thread there odd.

nick-morhun avatar Feb 22 '19 12:02 nick-morhun

result.addSource() needs to be called on the main thread in case of the other call (ApiSuccessResponse case).

nick-morhun avatar Feb 22 '19 15:02 nick-morhun

Is this because loadFromDb() is already on main thread? I don't understand why there is a distinction.

dazza5000 avatar Feb 22 '19 21:02 dazza5000

Is this because loadFromDb() is already on main thread? I don't understand why there is a distinction.

https://github.com/googlesamples/android-architecture-components/blob/523ea80ed325f637bca3ee6d36f56442ad4f5219/GithubBrowserSample/app/src/main/java/com/android/example/github/repository/NetworkBoundResource.kt#L48

https://github.com/googlesamples/android-architecture-components/blob/523ea80ed325f637bca3ee6d36f56442ad4f5219/GithubBrowserSample/app/src/main/java/com/android/example/github/repository/NetworkBoundResource.kt#L67

fetchFromNetwork() is already on main thread, so we need not switch to main thread any more.

xiaobailong24 avatar Feb 25 '19 02:02 xiaobailong24

Could somebody review this pr, and could it be merged?

xiaobailong24 avatar Mar 20 '19 02:03 xiaobailong24