Skip to content

Commit a99e2d1

Browse files
committed
Update to use lifecycle
1 parent a53fce2 commit a99e2d1

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let package = Package(
2424
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
2525
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.6.0"),
2626
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.9.0"),
27+
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"),
2728
],
2829
targets: [
2930
.executableTarget(
@@ -52,6 +53,7 @@ let package = Package(
5253
dependencies: [
5354
.product(name: "Crypto", package: "swift-crypto"),
5455
.product(name: "AsyncHTTPClient", package: "async-http-client"),
56+
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
5557
.target(name: "APNSCore"),
5658
]
5759
),

Sources/APNS/APNSClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import NIOHTTP1
2222
import NIOSSL
2323
import NIOTLS
2424
import NIOPosix
25+
import ServiceLifecycle
2526

2627
/// A client to talk with the Apple Push Notification services.
27-
public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder>: APNSClientProtocol {
28+
public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder>: Service, APNSClientProtocol {
2829

2930
/// The configuration used by the ``APNSClient``.
3031
private let configuration: APNSClientConfiguration
@@ -112,9 +113,8 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
112113
)
113114
}
114115
}
115-
116-
/// Shuts down the client gracefully.
117-
public func shutdown() async throws {
116+
117+
public func run() async throws {
118118
try await self.httpClient.shutdown()
119119
}
120120
}

Sources/APNS/Coding/APNSJSONDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import NIOFoundationCompat
1818

1919
/// A protocol that is similar to the `JSONDecoder`. This allows users of APNSwift to customize the decoder used
2020
/// for decoding the APNS response bodies.
21-
public protocol APNSJSONDecoder {
21+
public protocol APNSJSONDecoder: Sendable {
2222
func decode<T: Decodable>(_ type: T.Type, from buffer: ByteBuffer) throws -> T
2323
}
2424

Sources/APNS/Coding/APNSJSONEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import NIOFoundationCompat
1818

1919
/// A protocol that is similar to the `JSONEncoder`. This allows users of APNSwift to customize the encoder used
2020
/// for encoding the notification JSON payloads.
21-
public protocol APNSJSONEncoder {
21+
public protocol APNSJSONEncoder: Sendable {
2222
func encode<T: Encodable>(_ value: T, into buffer: inout ByteBuffer) throws
2323
}
2424

Sources/APNSCore/APNSClient.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@
1414

1515
public protocol APNSClientProtocol {
1616
func send(_ request: APNSRequest<some APNSMessage>) async throws -> APNSResponse
17-
func shutdown() async throws
1817
}

Sources/APNSExample/Program.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct Main {
6464
logger.warning("error sending push: \(error)")
6565
}
6666

67-
try? await client.shutdown()
67+
try await client.run()
6868
}
6969
}
7070

0 commit comments

Comments
 (0)