File tree Expand file tree Collapse file tree 3 files changed +12
-5
lines changed
Tool/Sources/OpenAIService Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments