From 25e1447e7b1660074cf9cf1b9911ef015e97efa4 Mon Sep 17 00:00:00 2001 From: Kyle Browning Date: Tue, 20 Aug 2024 12:01:55 -0700 Subject: [PATCH] Updates --- .github/workflows/swift.yml | 6 +++--- Package.swift | 3 ++- Sources/APNS/APNSClient.swift | 16 +++------------- Sources/APNSCore/APNSClient.swift | 2 +- Sources/APNSExample/Program.swift | 14 ++++++-------- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index cb4c4f62..2bd8b5e9 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -4,21 +4,21 @@ on: jobs: focal: container: - image: swift:5.7-focal + image: swift:6.0-focal runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - run: swift test --enable-test-discovery thread: container: - image: swift:5.7-focal + image: swift:6.0-focal runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - run: swift test --enable-test-discovery --sanitize=thread address: container: - image: swift:5.7-focal + image: swift:6.0-focal runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 diff --git a/Package.swift b/Package.swift index bb0f66a7..c3956c59 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.9 +// swift-tools-version:6.0 import PackageDescription let package = Package( @@ -31,6 +31,7 @@ let package = Package( dependencies: [ .target(name: "APNSCore"), .target(name: "APNS"), + .product(name: "Logging", package: "swift-log"), ] ), .testTarget( diff --git a/Sources/APNS/APNSClient.swift b/Sources/APNS/APNSClient.swift index 7c318f96..a0e1dfd3 100644 --- a/Sources/APNS/APNSClient.swift +++ b/Sources/APNS/APNSClient.swift @@ -114,19 +114,9 @@ public final class APNSClient Void) { - self.httpClient.shutdown(callback) + /// Shuts down the client and event loop gracefully. + public func shutdown() async throws { + try await self.httpClient.shutdown() } } diff --git a/Sources/APNSCore/APNSClient.swift b/Sources/APNSCore/APNSClient.swift index 4efe6916..0cf89f26 100644 --- a/Sources/APNSCore/APNSClient.swift +++ b/Sources/APNSCore/APNSClient.swift @@ -16,5 +16,5 @@ import Dispatch public protocol APNSClientProtocol { func send(_ request: APNSRequest) async throws -> APNSResponse - func shutdown(queue: DispatchQueue, callback: @Sendable @escaping (Error?) -> Void) + func shutdown() async throws } diff --git a/Sources/APNSExample/Program.swift b/Sources/APNSExample/Program.swift index b4406ff2..e3192799 100644 --- a/Sources/APNSExample/Program.swift +++ b/Sources/APNSExample/Program.swift @@ -14,7 +14,7 @@ import APNSCore import APNS -import OSLog +import Logging import Foundation @available(macOS 11.0, *) @@ -30,8 +30,10 @@ struct Main { static let keyIdentifier = "" static let teamIdentifier = "" + private static let logger = Logger(label: "APNSwiftExample") + static func main() async throws { - let logger = Logger(subsystem: "apns", category: "apns-main") + let client = APNSClient( configuration: .init( authenticationMethod: .jwt( @@ -55,14 +57,10 @@ struct Main { try await Self.sendVoIP(with: client) try await Self.sendFileProvider(with: client) } catch { - logger.warning("error sending push:\(error)") + logger.warning("error sending push: \(error)") } - client.shutdown { error in - if let error = error { - logger.warning("error shutting down client: \(error.localizedDescription)") - } - } + try? await client.shutdown() } }