Can I write functions that work as both suspendabl...
# coroutines
k
Can I write functions that work as both suspendable and non-suspendable functions? My use case is a custom logging framework. Instead of having two separate interfaces, one with suuspendable and one without, functions, I would like to have one single interface that works on both. If the caller context is suspendable, then it uses suspendable functions. If not, it uses blocking ones. I am working on a multiplatform project. I'd like this API to be part of
commonMain
.
u
as far as i know, only way would be an inline function
a
non suspending functionsare invokable in both suspending and non suspending contexts, so just write your code with non suspending functions and both callers will be happy