mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[eel] eelProcessUtils: fix awaitExecutionResult
GitOrigin-RevId: dda515a0e193b8a30fd689f1e4bca937b9d2f431
This commit is contained in:
committed by
intellij-monorepo-bot
parent
59de2aef43
commit
283e345fbf
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user