diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5453fa8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + macos-14: + name: Build macOS 14 (Swift 5.10) + runs-on: macos-14 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + run: swift build -v + macos-15: + name: Build macOS 15 (Swift 6.0) + runs-on: macos-15 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v + ubuntu: + name: Build Linux + runs-on: ubuntu-latest + container: + image: swift:latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml deleted file mode 100644 index 67a622f..0000000 --- a/.github/workflows/linux.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Build Linux - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Build Linux - runs-on: ubuntu-latest - container: - image: swift:latest - steps: - - uses: actions/checkout@v4 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml deleted file mode 100644 index 98e74c9..0000000 --- a/.github/workflows/macos.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Build macOS - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Build macOS - runs-on: macos-15 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v diff --git a/Package.swift b/Package.swift index d348a6e..9d9d6be 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.7 +// swift-tools-version: 5.10 import PackageDescription @@ -9,6 +9,7 @@ let package = Package( .iOS(.v13), .tvOS(.v13), .watchOS(.v6), + .visionOS(.v1) ], products: [ .library( diff --git a/Package@swift-5.9.swift b/Package@swift-6.0.swift similarity index 76% rename from Package@swift-5.9.swift rename to Package@swift-6.0.swift index 53b4a19..66f1cc8 100644 --- a/Package@swift-5.9.swift +++ b/Package@swift-6.0.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 6.0 import PackageDescription @@ -18,8 +18,7 @@ let package = Package( ], targets: [ .target( - name: "EventSource", - swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]), + name: "EventSource"), .testTarget( name: "EventSourceTests", dependencies: ["EventSource"]), diff --git a/README.md b/README.md index 53d74f9..a112118 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # EventSource -[![Build macOS](https://github.com/Recouse/EventSource/actions/workflows/macos.yml/badge.svg)](https://github.com/Recouse/EventSource/actions/workflows/macos.yml) -[![Build Linux](https://github.com/Recouse/EventSource/actions/workflows/linux.yml/badge.svg)](https://github.com/Recouse/EventSource/actions/workflows/linux.yml) +[![CI](https://github.com/Recouse/EventSource/actions/workflows/ci.yml/badge.svg)](https://github.com/Recouse/EventSource/actions/workflows/ci.yml) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRecouse%2FEventSource%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/Recouse/EventSource) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRecouse%2FEventSource%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Recouse/EventSource) @@ -104,7 +103,7 @@ var response: String = "" for await event in await dataTask.events() { switch event { case .event(let event): - if let eventData = event.data, let data = eventData.data(using: .utf8) { + if let data = eventDevent.data?ata.data(using: .utf8) { let chunk = try? JSONDecoder().decode(ChatCompletionChunk.self, from: data) let string = chunk?.choices.first?.delta.content ?? "" response += string diff --git a/Sources/EventSource/EventSource.swift b/Sources/EventSource/EventSource.swift index fb6cffd..f5688b9 100644 --- a/Sources/EventSource/EventSource.swift +++ b/Sources/EventSource/EventSource.swift @@ -151,10 +151,19 @@ public extension EventSource { } } + #if compiler(>=6.0) continuation.onTermination = { @Sendable [weak self] _ in sesstionDelegateTask.cancel() Task { await self?.close() } } + #else + continuation.onTermination = { @Sendable _ in + sesstionDelegateTask.cancel() + Task { [weak self] in + await self?.close() + } + } + #endif self.continuation = continuation