Jonathan Walsh
07/31/2018, 5:07 PMasCompletableFuture
. It seems to hang if my coroutine throws an exception.
class CompletableFutureTest {
@Test
fun testFailAsCompletableFuture() {
val executeJob = async {
fail("Test failed predictably")
}
val future = executeJob.asCompletableFuture()
println("### asCompletableFuture")
future.get()
println("### Execute job completed!")
}
}
I get this stacktrace in the log
Exception in thread "ForkJoinPool.commonPool-worker-1 @coroutine#1" kotlinx.coroutines.experimental.CompletionHandlerException: Exception in completion handler InvokeOnCompletion[InvokeOnCompletion@377acc75] for "coroutine#1":DeferredCoroutine{CompletedExceptionally}@685fc50a
at kotlinx.coroutines.experimental.JobSupport.completeUpdateState(JobSupport.kt:226)
at kotlinx.coroutines.experimental.JobSupport.updateState(JobSupport.kt:157)
at kotlinx.coroutines.experimental.JobSupport.makeCompletingInternal(JobSupport.kt:568)
at kotlinx.coroutines.experimental.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:552)
at kotlinx.coroutines.experimental.AbstractCoroutine.resumeWithException(AbstractCoroutine.kt:110)
at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:150)
at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:14)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.AssertionError: Test failed predictably
at org.junit.Assert.fail(Assert.java:88)
at kotlin.test.junit.JUnitAsserter.fail(JUnitSupport.kt:56)
at kotlin.test.AssertionsKt__AssertionsKt.fail(Assertions.kt:89)
at kotlin.test.AssertionsKt.fail(Unknown Source)
at completable.future.test.CompletableFutureTest$testFailAsCompletableFuture$executeJob$1.doResume(CompletableFutureTest.kt:14)
at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:42)
... 7 more
Vsevolod Tolstopyatov [JB]
07/31/2018, 8:07 PMJonathan Walsh
08/01/2018, 12:04 AM