Hey. In general, do I need to include a dependency...
# coroutines
a
Hey. In general, do I need to include a dependency on the coroutines library in a module to write a
suspend fun
? I’m asking about it only because I’m trying to optimise some modules’ dependencies (e.g. get rid of unnecessary
implementation
/
api
dependencies)
e
a basic
suspend fun
may not need any external dependencies; the compiler and stdlib contain core coroutines functionality. but many things you may want to do in a suspending function will depend on the kotlinx.coroutines library
n
What's available in stdlib is listed here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/ There's no
CoroutineScope
Job
launch
delay
CoroutineDispatcher
.
a
The lack of
suspendCancellableCoroutine
is going to mean that any suspend functions you write this way won't be cancellable either (unless you're calling something else that brings in kotlinx.coroutines as a transitive dependency)
e
or perhaps you write a higher-order function - if invoking a given cancellable suspend fun, it should be cancellable - but yeah. in order to properly bridge the blocking and suspending worlds in a way that cooperates with kotlinx.coroutines, you need kotlinx.coroutines
1
a
In my case I wanted to have an interface with a suspend fun method without any implementation in that module. Thanks for all your answers
a
Sure, that would work. I'd expect that module to grow and need it before too long though; callers expecting cancellability of that interface method is going to drive quite a bit