https://kotlinlang.org logo
#coroutines
Title
# coroutines
i

igorvd

05/29/2018, 12:07 PM
Hi guys, another question of how are you using coroutines... In the context of
clean architecture
, how you guys model the coroutines execution for use cases? You guys only mark the execute method with suspend and let the caller decide how to start the suspend function, or make the suspend function return a deferred or result?
v

voddan

05/29/2018, 2:20 PM
Our team treats
suspend
as a part of a function contract and marks with it every function which potentially can do IO (http or database access), even if the current implementation of the function is blocking. That plays out very nicely when, for example, we update a framework and it re-implements some operation in an async way, all we have to do is to add an adapter in one place, and all the other code keeps working.
b

bdawg.io

05/29/2018, 7:10 PM
It’s probably best to only do
suspend
if your function is actually going to suspend — so if you choose to do IO, make sure it’s IO that can suspend and not just be marked suspend but actually be blocking
suspend
isn’t free
5 Views