Amanjeet Singh
04/27/2020, 5:07 AMcommonMain
using coroutines. Normally, the methods in android would be marked by suspend
and then they can fetch any data from remote or local. Also writing tests to this on JVM (Android in my case) is easy as we can create a runBlocking
and assert the results. But when it comes to iOS we don't have any suspend
methods and thus the same function cannot be tested and thus we end up adding a high order function which will give you an onSuccess
or onFailure
when launch
coroutine gives result.
This seems to be a bit messy to me because in common we end up maintaining 2 implementations for fetching same data each for android and iOS. (common is not "common" anymore in this case)
I need an approach which can be directly exposed to both worlds with unit tests also working on both sides. How you guys create repositories and unit test them? Advices and approaches would be appreciated 🙂edenman
04/27/2020, 5:32 AMedenman
04/27/2020, 5:32 AMKurt Renzo Acosta
04/27/2020, 5:51 AMJurriaan Mous
04/27/2020, 6:16 AMedenman
04/27/2020, 9:56 AMKurt Renzo Acosta
04/27/2020, 9:57 AMOrhan Tozan
05/09/2020, 2:05 AMedenman
05/09/2020, 2:06 AMfun fooWithCallback(callback: (MyObject) -> Unit) {
scope.launch {
val result = foo()
callback(result)
}
}
Orhan Tozan
05/09/2020, 2:07 AMscope
be? (Lets say this method is in a UserRepository)Orhan Tozan
05/09/2020, 2:11 AMMainScope
?edenman
05/09/2020, 2:25 AMCoroutineScope(Dispatcher)
where Dispatcher is a CoroutineDispatcher
and it does
dispatch_async(queue) {
block.run()
}
Orhan Tozan
05/09/2020, 2:33 AMedenman
05/09/2020, 2:33 AMDispatcher
so each platform can kick off stuff how they wantedenman
05/09/2020, 2:34 AMOrhan Tozan
05/09/2020, 2:36 AMOrhan Tozan
05/09/2020, 2:36 AMedenman
05/09/2020, 2:43 AMedenman
05/09/2020, 2:43 AMedenman
05/09/2020, 2:43 AMOrhan Tozan
05/09/2020, 2:47 AMedenman
05/09/2020, 8:00 PM