Ben Butterworth
02/02/2021, 6:15 PMwithContext(context)
or async(context) {}
) and return Deferred
, or should callers have the responsibility to select the context? I would think its cleaner to encapsulate the context choice to a lower level function itself.
Fragment/Activity calls ViewModel calls Service calls API. The Service returns a Result<T>
, and I originally made ViewModel functions return Deferred<T>
, so Fragments need to await
it. However, I found lots of examples calling async {}
everywhere the functions are called, so callers need to know which context to use, which they will likely know less than the API designer. Also, the withContext
coroutine function seems to imply people should be calling it in fragments/ highest level. I assume this because withContext
seems ‘terminal’ (it suspends until it completes).
I am still working on my coroutine understanding, so I would appreciate any help 🙂Dominaezzz
02/02/2021, 6:25 PMBen Butterworth
02/02/2021, 6:25 PMuli
02/03/2021, 11:09 PMBen Butterworth
02/05/2021, 9:54 AM