Skip to content

Commit 67221f4

Browse files
committed
Update
1 parent 46da74c commit 67221f4

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Core/Sources/ChatGPTChatTab/Chat.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct Chat: ReducerProtocol {
9999
case observeSystemPromptChange(UUID)
100100
case observeExtraSystemPromptChange(UUID)
101101
case observeDefaultScopesChange(UUID)
102+
case sendMessage(UUID)
102103
}
103104

104105
@Dependency(\.openURL) var openURL
@@ -129,16 +130,19 @@ struct Chat: ReducerProtocol {
129130
state.typedMessage = ""
130131
return .run { _ in
131132
try await service.send(content: message)
132-
}
133+
}.cancellable(id: CancelID.sendMessage(id))
133134

134135
case .returnButtonTapped:
135136
state.typedMessage += "\n"
136137
return .none
137138

138139
case .stopRespondingButtonTapped:
139-
return .run { _ in
140-
await service.stopReceivingMessage()
141-
}
140+
return .merge(
141+
.run { _ in
142+
await service.stopReceivingMessage()
143+
},
144+
.cancel(id: CancelID.sendMessage(id))
145+
)
142146

143147
case .clearButtonTap:
144148
return .run { _ in

Core/Sources/ChatService/ChatService.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public final class ChatService: ObservableObject {
105105

106106
let stream = try await chatGPTService.send(content: content, summary: nil)
107107
do {
108-
for try await _ in stream {}
108+
for try await _ in stream {
109+
try Task.checkCancellation()
110+
}
109111
} catch {}
110112
}
111113

Tool/Sources/OpenAIService/ChatGPTService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public class ChatGPTService: ChatGPTServiceType {
203203
}
204204
}
205205

206+
#warning("TODO: remove this and let the concurrency system handle it")
206207
public func stopReceivingMessage() {
207208
runningTask?.cancel()
208209
runningTask = nil

0 commit comments

Comments
 (0)