hey guys, short question: Is there a way to define...
# coroutines
r
hey guys, short question: Is there a way to define a block which is a suspend function?
Copy code
suspend fun magic(token: String) {}

fun tokenMagic(refreshToken: String, work: (String)->Unit) =
        runBlocking {
            fetchToken(refreshToken)
        }?.let(work::invoke)

fun example() {
    tokenMagic("42") { token ->
        magic(token) // magic should be only called from a coroutine
    }
}
I would like to execute "work" within a runBlocking block, so that I doesn't need to add a runBlocking statment for each usage of
tokenMagic
m
Mark the lambda with the
suspend
modifier:
work: suspend (String) -> Unit
r
oh really there the keyword should be there. I feel so stupid 😄
yes it seems to work thank you!
m
No problem 👍