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

Update to use lifecycle #212

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.6.0"),
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.9.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"),
],
targets: [
.executableTarget(
Expand Down Expand Up @@ -52,6 +53,7 @@ let package = Package(
dependencies: [
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
.target(name: "APNSCore"),
]
),
Expand Down
9 changes: 5 additions & 4 deletions Sources/APNS/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import NIOHTTP1
import NIOSSL
import NIOTLS
import NIOPosix
import ServiceLifecycle

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

/// The configuration used by the ``APNSClient``.
private let configuration: APNSClientConfiguration
Expand Down Expand Up @@ -112,9 +113,9 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
)
}
}

/// Shuts down the client gracefully.
public func shutdown() async throws {
public func run() async throws {
try await gracefulShutdown()
try await self.httpClient.shutdown()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/APNS/Coding/APNSJSONDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NIOFoundationCompat

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

Expand Down
2 changes: 1 addition & 1 deletion Sources/APNS/Coding/APNSJSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NIOFoundationCompat

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

Expand Down
1 change: 0 additions & 1 deletion Sources/APNSCore/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@

public protocol APNSClientProtocol {
func send(_ request: APNSRequest<some APNSMessage>) async throws -> APNSResponse
func shutdown() async throws
}
3 changes: 2 additions & 1 deletion Sources/APNSExample/Program.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ struct Main {
logger.warning("error sending push: \(error)")
}

try? await client.shutdown()
try await client.run()

}
}

Expand Down
52 changes: 0 additions & 52 deletions Tests/APNSTests/APNSClientTests.swift

This file was deleted.