Ryan Smith
02/21/2023, 1:34 AMRyan Smith
02/21/2023, 1:34 AMApkDataRepository
class to manage APK data, and the data source is just a private MutableStateFlow
property of the repository itself.
In trying to adhere to advice from different things I've read, my repository exposes the data as a Flow
and CRUD methods as suspending functions. IntelliJ is indicating that all of the suspend modifiers on my ApkDataRepository
functions are redundant so I'm feeling like I did something wrong there. I'm trying out another simple app and would like to learn from my past mistakes, so any advice or examples is appreciated.
I've considered that maybe suspending functions and Flow
are just overkill for such a simple app, but at the same time hope that it's possible to use contrived, low-complexity use cases like this to better understand coroutine and Flow concepts.gildor
02/21/2023, 4:28 AMIntelliJ is indicating that all of the suspend modifiers on myIt indeed looks as something wrong suspend function needed only if it calls another suspend function And 2 main reasons why you may need suspend function is: 1. You work with some asyncronous API (based on callbacks, observer pattern etc) and use coroutine adapater to work with it 2. Use suspend functions to run some work in a separate thread using coroutines dispatchersfunctions are redundant so I’m feeling like I did something wrong thereApkDataRepository
gildor
02/21/2023, 4:30 AMgildor
02/21/2023, 4:31 AMRyan Smith
02/21/2023, 11:38 PMMap
or some other data structure in memory. In theory it would be easy enough to plug-in a database or network data source if all my data layer code is structured well enough, but I was hoping to not have to start with that right from the beginning while I learn my way around.Ryan Smith
02/21/2023, 11:38 PMgildor
02/22/2023, 1:53 AMI suppose what I’m aiming for is making my data layer’s API asynchronous, even if in reality it’s just updating asuspend function by itself doesn’t make your code asyncroonous, but if you use something like a standalone coroutine (launch/async) or some flow to use it to update your Map, it will emulate case with network or databaseMap
Ryan Smith
02/22/2023, 2:01 AMcreate
operation would serialize a JSON object of default values to disk. A get
would deserialize the file, and then emit a single value on a Flow
. An update
would re-serialize the file with updated values, and delete
would remove a particular file.gildor
02/22/2023, 2:01 AM