Skip to content

Commit 209c62f

Browse files
committed
updating for strict concurrency
1 parent 6433378 commit 209c62f

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

Package.swift

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.9
22
import PackageDescription
33

44
let package = Package(
@@ -31,17 +31,25 @@ let package = Package(
3131
dependencies: [
3232
.target(name: "APNSCore"),
3333
.target(name: "APNS"),
34-
]),
34+
]
35+
),
3536
.testTarget(
3637
name: "APNSTests",
3738
dependencies: [
3839
.target(name: "APNSCore"),
3940
.target(name: "APNS"),
40-
]),
41+
],
42+
swiftSettings: [
43+
.enableExperimentalFeature("StrictConcurrency")
44+
]
45+
),
4146
.target(
4247
name: "APNSCore",
4348
dependencies: [
4449
.product(name: "Crypto", package: "swift-crypto"),
50+
],
51+
swiftSettings: [
52+
.enableExperimentalFeature("StrictConcurrency")
4553
]
4654
),
4755
.target(
@@ -50,6 +58,9 @@ let package = Package(
5058
.product(name: "Crypto", package: "swift-crypto"),
5159
.product(name: "AsyncHTTPClient", package: "async-http-client"),
5260
.target(name: "APNSCore"),
61+
],
62+
swiftSettings: [
63+
.enableExperimentalFeature("StrictConcurrency")
5364
]
5465
),
5566
.target(
@@ -62,12 +73,18 @@ let package = Package(
6273
.product(name: "NIOSSL", package: "swift-nio-ssl"),
6374
.product(name: "NIOHTTP1", package: "swift-nio"),
6475
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
76+
],
77+
swiftSettings: [
78+
.enableExperimentalFeature("StrictConcurrency")
6579
]
6680
),
6781
.target(
6882
name: "APNSURLSession",
6983
dependencies: [
7084
.target(name: "APNSCore"),
85+
],
86+
swiftSettings: [
87+
.enableExperimentalFeature("StrictConcurrency")
7188
]
7289
),
7390
]

Sources/APNS/APNSClient.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,9 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
125125
/// - Parameters:
126126
/// - queue: The queue on which the callback is invoked on.
127127
/// - callback: The callback that is invoked when everything is shutdown.
128-
@preconcurrency public func shutdown(queue: DispatchQueue = .global(), callback: @Sendable @escaping (Error?) -> Void) {
128+
public func shutdown(queue: DispatchQueue = .global(), callback: @Sendable @escaping (Error?) -> Void) {
129129
self.httpClient.shutdown(callback)
130130
}
131-
132-
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
133-
public func syncShutdown() throws {
134-
try self.httpClient.syncShutdown()
135-
}
136131
}
137132

138133
extension APNSClient: Sendable where Decoder: Sendable, Encoder: Sendable {}

Sources/APNSCore/APNSClient.swift

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Dispatch
16+
1517
public protocol APNSClientProtocol {
1618
func send(_ request: APNSRequest<some APNSMessage>) async throws -> APNSResponse
19+
func shutdown(queue: DispatchQueue, callback: @Sendable @escaping (Error?) -> Void)
1720
}

Sources/APNSExample/Program.swift

+20-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import APNSCore
1616
import APNS
17+
import OSLog
1718
import Foundation
1819

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

3233
static func main() async throws {
34+
let logger = Logger(subsystem: "apns", category: "apns-main")
3335
let client = APNSClient(
3436
configuration: .init(
3537
authenticationMethod: .jwt(
@@ -43,15 +45,24 @@ struct Main {
4345
responseDecoder: JSONDecoder(),
4446
requestEncoder: JSONEncoder()
4547
)
46-
47-
try await Self.sendSimpleAlert(with: client)
48-
try await Self.sendLocalizedAlert(with: client)
49-
try await Self.sendThreadedAlert(with: client)
50-
try await Self.sendCustomCategoryAlert(with: client)
51-
try await Self.sendMutableContentAlert(with: client)
52-
try await Self.sendBackground(with: client)
53-
try await Self.sendVoIP(with: client)
54-
try await Self.sendFileProvider(with: client)
48+
do {
49+
try await Self.sendSimpleAlert(with: client)
50+
try await Self.sendLocalizedAlert(with: client)
51+
try await Self.sendThreadedAlert(with: client)
52+
try await Self.sendCustomCategoryAlert(with: client)
53+
try await Self.sendMutableContentAlert(with: client)
54+
try await Self.sendBackground(with: client)
55+
try await Self.sendVoIP(with: client)
56+
try await Self.sendFileProvider(with: client)
57+
} catch {
58+
logger.warning("error sending push:\(error)")
59+
}
60+
61+
client.shutdown { error in
62+
if let error = error {
63+
logger.warning("error shutting down client: \(error.localizedDescription)")
64+
}
65+
}
5566
}
5667
}
5768

0 commit comments

Comments
 (0)