mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[debugger] RIDER-141781 Review fixes IJ-CR-219419
(cherry picked from commit 53d1fc67fb6a1cbe45f4737ca8ebfed70e6f1f9c) GitOrigin-RevId: 9de2befa307f4a313cac85dc3fab34e89e933b93
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f757637a8b
commit
fa00552fe4
+10
-13
@@ -9,10 +9,8 @@ import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.completeWith
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.selects.select
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
|
||||
/**
|
||||
@@ -58,22 +56,21 @@ internal class SequentialRpcRequestsExecutor private constructor() {
|
||||
|
||||
override suspend fun performRequest() {
|
||||
if (!result.isActive) return
|
||||
|
||||
supervisorScope {
|
||||
val requestResult = async { request() }
|
||||
select {
|
||||
requestResult.onJoin {
|
||||
result.completeWith(runCatching { requestResult.await() })
|
||||
}
|
||||
result.onJoin {
|
||||
requestResult.cancelAndJoin()
|
||||
}
|
||||
try {
|
||||
supervisorScope {
|
||||
val requestResult = async { request() }
|
||||
result.invokeOnCompletion { requestResult.cancel() }
|
||||
result.completeWith(runCatching { requestResult.await() })
|
||||
}
|
||||
}
|
||||
finally {
|
||||
result.cancel()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun markUndelivered() {
|
||||
this.result.cancel()
|
||||
result.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
@@ -5,6 +5,7 @@ import com.intellij.platform.debugger.impl.frontend.util.SequentialRpcRequestsEx
|
||||
import com.intellij.platform.util.coroutines.childScope
|
||||
import com.intellij.testFramework.LoggedErrorProcessor
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
@@ -155,6 +156,28 @@ internal class SequentialRpcRequestsExecutorTest {
|
||||
assertTrue(request.isCancelled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cancelling executor scope cancels running and queued requests`() = runBlocking {
|
||||
val scope = childScope("SequentialRpcRequestsExecutor")
|
||||
val executor = SequentialRpcRequestsExecutor.create(scope)
|
||||
val requestStarted = CompletableDeferred<Unit>()
|
||||
val runningRequest = executor.submit {
|
||||
requestStarted.complete(Unit)
|
||||
awaitCancellation()
|
||||
}
|
||||
val queuedRequest = executor.submit {
|
||||
error("Queued request must not be executed")
|
||||
}
|
||||
|
||||
requestStarted.await()
|
||||
scope.cancel()
|
||||
runningRequest.join()
|
||||
queuedRequest.join()
|
||||
|
||||
assertTrue(runningRequest.isCancelled)
|
||||
assertTrue(queuedRequest.isCancelled)
|
||||
}
|
||||
|
||||
private fun runTest(test: suspend (SequentialRpcRequestsExecutor) -> Unit) = runBlocking {
|
||||
val scope = childScope("SequentialRpcRequestsExecutor")
|
||||
val executor = SequentialRpcRequestsExecutor.create(scope)
|
||||
|
||||
Reference in New Issue
Block a user