Jossi Wolf
1 min readJul 15, 2020

--

Sorry, that might not have been explicit enough. `map` can easily be called from another thread - this example was assuming it was being called off the main thread, under the assumption that that would prevent any issues.

You should definitely not be reading from the db or doing any long-running operation on the main thread! It would be great if the existing setup in the project would have caught this, but it didn't. Ideally, the storage solution does its work off the main thread, but in some setups (like ours), it might not.

There was indeed some serious logic happening! Sadly, the code is proprietary, so I couldn't post any actual pieces, but that's exactly what was going on. With Google recommending/having recommended using LiveData in Repositories before, you can almost be certain that hundreds of apps out there have issues like these.

--

--

Jossi Wolf
Jossi Wolf

Written by Jossi Wolf

Software Engineer @Google working on Jetpack Compose. I like Kotlin, Animations and Rabbits! speakerdeck.com/jossiwolf

No responses yet