Recouse / EventSource

Server-sent events in Swift
MIT License
31 stars 6 forks source link

EventSource return in wrong order #3

Closed lookou closed 7 months ago

lookou commented 1 year ago

I find that this eventsource received openai stream in wrong order . the ` let eventSource = EventSource(request: urlRequest)

    eventSource.maxRetryCount = 1
    eventSource.connect()

    Task{
        for await event in eventSource.events {
            switch event {
            case .open:
                print("Connection was opened.")
            case .error(let error):
                print("Received an error:", error.localizedDescription)
            case .message(let message):
                if (message.data != nil){
                    print("Received a message", message.data ?? "")
                    let res = json2Dict(jsonString: message.data!)
                    if res != nil {
                        completion(res!)
                    } else {
                        print("receieved res empty")
                    }
                } else {
                    print("messaeg data empty")
                }
            case .closed:
                print("Connection was closed.")
            }
        }
    }

`

any thing wrong with the code?

Recouse commented 1 year ago

Hello, Yes, it's a known bug. I'm working on a fix. Thank you for the report 👍

rhematt commented 7 months ago

Any update to this?

Recouse commented 7 months ago

Fixed in #11