Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating project for strict concurrency and Swift 6 #207

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
import PackageDescription
kylebrowning marked this conversation as resolved.
Show resolved Hide resolved

let package = Package(
Expand Down Expand Up @@ -31,17 +31,25 @@ let package = Package(
dependencies: [
.target(name: "APNSCore"),
.target(name: "APNS"),
]),
]
),
.testTarget(
name: "APNSTests",
dependencies: [
.target(name: "APNSCore"),
.target(name: "APNS"),
]),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
kylebrowning marked this conversation as resolved.
Show resolved Hide resolved
),
.target(
name: "APNSCore",
dependencies: [
.product(name: "Crypto", package: "swift-crypto"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
Expand All @@ -50,6 +58,9 @@ let package = Package(
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.target(name: "APNSCore"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
Expand All @@ -62,12 +73,18 @@ let package = Package(
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "APNSURLSession",
dependencies: [
.target(name: "APNSCore"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
]
Expand Down
7 changes: 1 addition & 6 deletions Sources/APNS/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,9 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
/// - Parameters:
/// - queue: The queue on which the callback is invoked on.
/// - callback: The callback that is invoked when everything is shutdown.
@preconcurrency public func shutdown(queue: DispatchQueue = .global(), callback: @Sendable @escaping (Error?) -> Void) {
public func shutdown(queue: DispatchQueue = .global(), callback: @Sendable @escaping (Error?) -> Void) {
kylebrowning marked this conversation as resolved.
Show resolved Hide resolved
self.httpClient.shutdown(callback)
}

/// Shuts down the client and `EventLoopGroup` if it was created by the client.
public func syncShutdown() throws {
try self.httpClient.syncShutdown()
}
}

extension APNSClient: Sendable where Decoder: Sendable, Encoder: Sendable {}
Expand Down
3 changes: 3 additions & 0 deletions Sources/APNSCore/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
//
//===----------------------------------------------------------------------===//

import Dispatch
kylebrowning marked this conversation as resolved.
Show resolved Hide resolved

public protocol APNSClientProtocol {
func send(_ request: APNSRequest<some APNSMessage>) async throws -> APNSResponse
func shutdown(queue: DispatchQueue, callback: @Sendable @escaping (Error?) -> Void)
kylebrowning marked this conversation as resolved.
Show resolved Hide resolved
}
29 changes: 20 additions & 9 deletions Sources/APNSExample/Program.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import APNSCore
import APNS
import OSLog
kylebrowning marked this conversation as resolved.
Show resolved Hide resolved
import Foundation

@available(macOS 11.0, *)
Expand All @@ -30,6 +31,7 @@ struct Main {
static let teamIdentifier = ""

static func main() async throws {
let logger = Logger(subsystem: "apns", category: "apns-main")
let client = APNSClient(
configuration: .init(
authenticationMethod: .jwt(
Expand All @@ -43,15 +45,24 @@ struct Main {
responseDecoder: JSONDecoder(),
requestEncoder: JSONEncoder()
)

try await Self.sendSimpleAlert(with: client)
try await Self.sendLocalizedAlert(with: client)
try await Self.sendThreadedAlert(with: client)
try await Self.sendCustomCategoryAlert(with: client)
try await Self.sendMutableContentAlert(with: client)
try await Self.sendBackground(with: client)
try await Self.sendVoIP(with: client)
try await Self.sendFileProvider(with: client)
do {
try await Self.sendSimpleAlert(with: client)
try await Self.sendLocalizedAlert(with: client)
try await Self.sendThreadedAlert(with: client)
try await Self.sendCustomCategoryAlert(with: client)
try await Self.sendMutableContentAlert(with: client)
try await Self.sendBackground(with: client)
try await Self.sendVoIP(with: client)
try await Self.sendFileProvider(with: client)
} catch {
logger.warning("error sending push:\(error)")
}

client.shutdown { error in
if let error = error {
logger.warning("error shutting down client: \(error.localizedDescription)")
}
}
}
}

Expand Down
Loading