https://kotlinlang.org logo
Title
e

Exerosis

12/18/2021, 4:22 PM
var resumePoint: Continuation<String>? = null
var hasJumpedBack = false
suspend fun test() = suspendCoroutineUninterceptedOrReturn<String> {
    resumePoint = it
    "Hello "
}

fun jumpBack() {
    if (!hasJumpedBack) {
        hasJumpedBack = true
        resumePoint?.resume("World")
    }
}
runBlocking {
    println("Starting")
    val result = test()
    println(result)
    jumpBack()
}
It had to be tested
j

Joffrey

12/18/2021, 5:46 PM
But why? You could use
CompletableDeferred
for this kind of use case
e

Exerosis

12/18/2021, 5:49 PM
How so? Also IDK why, it's just interesting.
j

Joffrey

12/18/2021, 7:43 PM
I'm afk so it's not easy to write code, but basically
resumePoint
could be a
CompletableDeferred
that you
await
in
test()
and complete successfully in
jumpBack()
e

Exerosis

12/18/2021, 9:20 PM
no because when you call .await() it will wait until it's completed before it executes jumpBack()
j

Joffrey

12/18/2021, 9:31 PM
Ah ok I wasn't sure what you were trying to achieve here. I guess you were just trying to break
suspendCoroutineUninterceptedOrReturn
😆
e

Exerosis

12/18/2021, 9:44 PM
Yes