Skip to content

Commit b97922e

Browse files
committed
Terminate process on cancellation
1 parent f76ec92 commit b97922e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Core/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ let package = Package(
148148
dependencies: ["OpenAIService"]
149149
),
150150
.target(name: "Preferences"),
151-
.target(name: "ChatPlugins", dependencies: ["OpenAIService", "Environment"]),
151+
.target(name: "ChatPlugins", dependencies: ["OpenAIService", "Environment", "Terminal"]),
152152
.target(name: "Terminal"),
153153
.target(name: "ChatService", dependencies: ["OpenAIService", "ChatPlugins", "Environment"]),
154154
]

Core/Sources/ChatPlugins/TerminalChatPlugin.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public actor TerminalChatPlugin: ChatPlugin {
9090
delegate?.pluginDidEnd(self)
9191
}
9292

93-
public func cancel() {
93+
public func cancel() async {
9494
isCancelled = true
95+
await terminal.terminate()
9596
}
9697
}

Core/Sources/Terminal/Terminal.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public protocol TerminalType {
1515
currentDirectoryPath: String,
1616
environment: [String: String]
1717
) async throws -> String
18+
19+
func terminate() async
1820
}
1921

2022
public final class Terminal: TerminalType, @unchecked Sendable {
@@ -145,4 +147,9 @@ public final class Terminal: TerminalType, @unchecked Sendable {
145147
inputPipe?.fileHandleForWriting.write(data)
146148
inputPipe?.fileHandleForWriting.closeFile()
147149
}
150+
151+
public func terminate() async {
152+
process?.terminate()
153+
process = nil
154+
}
148155
}

0 commit comments

Comments
 (0)