Skip to content

Commit 6a3f17f

Browse files
qwwdfsadelizarov
authored andcommitted
Unpark runBlocking thread on coroutine completion instead of cancellation
Fixes #501
1 parent 811c658 commit 6a3f17f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

core/kotlinx-coroutines-core/src/Builders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private class BlockingCoroutine<T>(
5656
if (privateEventLoop) require(eventLoop is BlockingEventLoop)
5757
}
5858

59-
override fun onCancellationInternal(exceptionally: CompletedExceptionally?) {
59+
override fun onCompletionInternal(state: Any?, mode: Int) {
6060
// wake up blocked thread
6161
if (Thread.currentThread() != blockedThread)
6262
LockSupport.unpark(blockedThread)

core/kotlinx-coroutines-core/test/RunBlockingTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,20 @@ class RunBlockingTest : TestBase() {
6666
finish(4)
6767
thread.close()
6868
}
69+
70+
71+
@Test
72+
fun testCancellation() {
73+
val job = launch(DefaultDispatcher) {
74+
runBlocking(coroutineContext) {
75+
while(true) {
76+
yield()
77+
}
78+
}
79+
}
80+
81+
runBlocking {
82+
job.cancelAndJoin()
83+
}
84+
}
6985
}

0 commit comments

Comments
 (0)