Hello, World! Let's say I have a fun to which I w...
# coroutines
b
Hello, World! Let's say I have a fun to which I want to pass a lambda - and in certain cases it would make sense to pass it a
suspend
lambda. I think there's 2 way I can do this: • have 2 different functions: something like
handle(onSuccess: () -> Unit)
and
handleSuspend(onSuccess: suspend () -> Unit)
• just have the suspend version and it can also accept a regular (non suspend) lambda My question is is there a performance penalty (or otherwise) in doing the second option?
l
Technically the suspendability implies an overhead even when no suspension occurs (which is why you need to specify it explicitly), but this is the kind of micro optimization you shouldn't care about unless its absolutely performance critical (in which case you should benchmark it anyway)
b
sounds good 🙂 Thanks!
k
Or you could have the function inlined, depending on what is in the function.