When PipeAsStringHandler is destroyed, ensure that we flush any pending data

Otherwise, we would not handle the last line if it didn’t end with a newline character.
This commit is contained in:
Alex Hoppen
2025-08-28 09:04:37 +02:00
parent 47ca76bb32
commit fbaa7ce75e

View File

@@ -27,6 +27,14 @@ package actor PipeAsStringHandler {
self.handler = handler
}
deinit {
if !buffer.isEmpty {
queue.async { [handler, buffer] in
handler(String(data: buffer, encoding: .utf8) ?? "<invalid UTF-8>")
}
}
}
private func handleDataFromPipeImpl(_ newData: Data) {
self.buffer += newData
while let newlineIndex = self.buffer.firstIndex(of: UInt8(ascii: "\n")) {