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

bod

02/26/2020, 2:01 PM
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

LastExceed

02/26/2020, 2:37 PM
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

bod

02/26/2020, 2:38 PM
sounds good 🙂 Thanks!
k

Kroppeb

02/26/2020, 4:24 PM
Or you could have the function inlined, depending on what is in the function.
2 Views