Skip to content

Commit

Permalink
Fix the infinite loop issue when WebSocket returns an error message i…
Browse files Browse the repository at this point in the history
…n the example case. (#3508)

* fix infinite loop issue when WebSocket receives an error message

* catch the error

* syntax update
  • Loading branch information
LukeWei authored Dec 3, 2024
1 parent 547d19c commit f6ae757
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,12 @@ extension WebSocketClient: DependencyKey {
return AsyncStream { continuation in
let task = Task {
while !Task.isCancelled {
continuation.yield(await Result { try await Message(socket.receive()) })
do {
let socketMessage = try await Message(socket.receive())
continuation.yield(.success(socketMessage))
} catch {
continuation.yield(.failure(error))
}
}
continuation.finish()
}
Expand Down

0 comments on commit f6ae757

Please sign in to comment.