[eel] eelProcessUtils: fix awaitExecutionResult

GitOrigin-RevId: dda515a0e193b8a30fd689f1e4bca937b9d2f431
This commit is contained in:
Andrii Zinchenko
2024-09-25 22:47:54 +02:00
committed by intellij-monorepo-bot
parent 59de2aef43
commit 283e345fbf

View File

@@ -5,7 +5,10 @@ import com.intellij.execution.processTools.ExecutionResult
import com.intellij.platform.eel.*
import com.intellij.util.io.computeDetached
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import java.io.ByteArrayOutputStream
import java.io.IOException
/**
@@ -38,10 +41,21 @@ fun EelExecApi.ExecuteProcessResult.unwrap() = when (this) {
*/
@OptIn(DelicateCoroutinesApi::class)
suspend fun EelProcess.awaitExecutionResult() = computeDetached {
val stdOut = async { stdout.receive() }
val stdErr = async { stderr.receive() }
ByteArrayOutputStream().use { out ->
ByteArrayOutputStream().use { err ->
coroutineScope {
launch {
stdout.consumeEach(out::write)
}
ExecutionResult(exitCode.await(), stdOut.await(), stdErr.await())
launch {
stderr.consumeEach(err::write)
}
}
ExecutionResult(exitCode.await(), out.toByteArray(), err.toByteArray())
}
}
}
/**