Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Sources/Subprocess/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,29 @@ public struct Configuration: Sendable {
let pid = spawnResults.execution.processIdentifier

var spawnResultBox: SpawnResult?? = consume spawnResults
var _spawnResult = spawnResultBox!.take()!

return try await withAsyncTaskCleanupHandler {
var _spawnResult = spawnResultBox!.take()!
let processIdentifier = _spawnResult.execution.processIdentifier

let result = try await withAsyncTaskCleanupHandler {
let inputIO = _spawnResult.inputWriteEnd()
let outputIO = _spawnResult.outputReadEnd()
let errorIO = _spawnResult.errorReadEnd()
let processIdentifier = _spawnResult.execution.processIdentifier

async let terminationStatus = try monitorProcessTermination(
forProcessWithIdentifier: processIdentifier
)
// Body runs in the same isolation
let result = try await body(_spawnResult.execution, inputIO, outputIO, errorIO)
return ExecutionResult(
terminationStatus: try await terminationStatus,
value: result
)
return try await body(_spawnResult.execution, inputIO, outputIO, errorIO)
} onCleanup: {
// Attempt to terminate the child process
await Execution.runTeardownSequence(
self.platformOptions.teardownSequence,
on: pid
)
}

return ExecutionResult(
terminationStatus: try await monitorProcessTermination(forProcessWithIdentifier: processIdentifier),
value: result
)
}
}

Expand Down
Loading