throws instead of delivering value when continuation is resumed on a different thread?
Copy code
suspend fun main() {
val failure = fail()
println(failure)
}
suspend fun fail() = suspendCoroutine<Result<String>> {
Executors.newSingleThreadExecutor().execute {
it.resume(Result.failure(RuntimeException()))
}
}
Copy code
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)
MiSikora
09/07/2020, 9:08 PM
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
MiSikora
09/08/2020, 12:03 PM
I’ll report an issue later if someone doesn’t beat me to it