https://kotlinlang.org logo
Title
m

MiSikora

09/07/2020, 7:37 PM
Is it expected that
kotlin.Result.Failure
throws instead of delivering value when continuation is resumed on a different thread?
suspend fun main() {
    val failure = fail()
    println(failure)
}

suspend fun fail() = suspendCoroutine<Result<String>> {
    Executors.newSingleThreadExecutor().execute {
        it.resume(Result.failure(RuntimeException()))
    }
}
Exception in thread "main" java.lang.RuntimeException
	at MainKt$fail$2$1.run(main.kt:12)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Making
fail()
function
inline
seems to resolve the issue. Anyone knows why that might be?
g

gildor

09/07/2020, 11:43 PM
It looks as the same issue which we have with Result, it's a bug of Kotlin 1.4.0-1.4.10 I tried 1.4.20 dev builda and it fixed there Could you also check? It's very nice that you have simple reproducible sample, I noticed this only because some of our tests are failed So it reproducible when there is double wrapping to Result: Result.success(Result.failure(...)), probably threading is what I missed when tried to reproduce
m

MiSikora

09/08/2020, 12:03 PM
I can’t confirm.
1.3.72
works properly, but
1.4.20-dev-3296-10
still fails
I’ll report an issue later if someone doesn’t beat me to it
g

gildor

09/08/2020, 2:16 PM
The latest dev build is https://bintray.com/kotlin/kotlin-dev/kotlin/1.4.20-dev-3898-14 Could you try it?
m

MiSikora

09/08/2020, 2:20 PM
Yeah, it’s fixed there
👍 2