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
ephemient
06/22/2022, 7:46 PM
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
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
ephemient
06/22/2022, 11:41 PM
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
azabost
06/24/2022, 6:02 AM
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
Adam Powell
06/24/2022, 2:07 PM
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