dimsuz
01/28/2020, 11:51 AMSingle
in coroutines? for example Single.fromCallable { doNetworkRequest() }
would emit only upon subscription. Should I just use Flow
which calls a suspending function inside? or is this too complex?scope.launch { doNetworkRequest() }
Is actually conceptually the same as Single.fromCallable
tseisel
01/28/2020, 12:25 PMlaunch
is hot. The conceptually closest to Single
is the following :
scope.async(start = CoroutineStart.LAZY) { doNetworkRequest() }
Note that you have to call deferred.await()
to trigger computationdimsuz
01/28/2020, 12:36 PM.start()
didn't know that awaiting would start it too. Missed it, it's actually mentioned in docselizarov
01/28/2020, 12:45 PMSingle
is a simple suspending function. It would “emit” (do something) only when you call it.dimsuz
01/28/2020, 12:52 PMSingle<>
for consumers, now I return suspend fun
and do this transitively through all app layers up to the point (e.g in UI) where in Rx I would call subscribe()
, but now I call launch()
elizarov
01/28/2020, 12:55 PMfun foo(): Single<T>
you now declare suspend fun foo(): T
which your consumers call when they need.dimsuz
01/28/2020, 12:56 PMelizarov
01/28/2020, 12:56 PMsubscribe
gets replaced with launch
. It is the correct analogy.dimsuz
01/28/2020, 12:57 PM