Skip to content

Commit

Permalink
updating for strict concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebrowning committed Aug 20, 2024
1 parent 6433378 commit 209c62f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
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

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")
]
),
.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) {
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

public protocol APNSClientProtocol {
func send(_ request: APNSRequest<some APNSMessage>) async throws -> APNSResponse
func shutdown(queue: DispatchQueue, callback: @Sendable @escaping (Error?) -> Void)
}
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
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

0 comments on commit 209c62f

Please sign in to comment.