Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebrowning committed Aug 20, 2024
1 parent 209c62f commit 25e1447
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ on:
jobs:
focal:
container:
image: swift:5.7-focal
image: swift:6.0-focal
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: swift test --enable-test-discovery
thread:
container:
image: swift:5.7-focal
image: swift:6.0-focal
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: swift test --enable-test-discovery --sanitize=thread
address:
container:
image: swift:5.7-focal
image: swift:6.0-focal
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0
import PackageDescription

let package = Package(
Expand Down Expand Up @@ -31,6 +31,7 @@ let package = Package(
dependencies: [
.target(name: "APNSCore"),
.target(name: "APNS"),
.product(name: "Logging", package: "swift-log"),
]
),
.testTarget(
Expand Down
16 changes: 3 additions & 13 deletions Sources/APNS/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,9 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
}
}

/// Shuts down the client and event loop gracefully. This function is clearly an outlier in that it uses a completion
/// callback instead of an EventLoopFuture. The reason for that is that NIO's EventLoopFutures will call back on an event loop.
/// The virtue of this function is to shut the event loop down. To work around that we call back on a DispatchQueue
/// instead.
///
/// - Important: This will only shutdown the event loop if the provider passed to the client was ``createNew``.
/// For shared event loops the owner of the event loop is responsible for handling the lifecycle.
///
/// - Parameters:
/// - queue: The queue on which the callback is invoked on.
/// - callback: The callback that is invoked when everything is shutdown.
public func shutdown(queue: DispatchQueue = .global(), callback: @Sendable @escaping (Error?) -> Void) {
self.httpClient.shutdown(callback)
/// Shuts down the client and event loop gracefully.
public func shutdown() async throws {
try await self.httpClient.shutdown()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/APNSCore/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import Dispatch

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

import APNSCore
import APNS
import OSLog
import Logging
import Foundation

@available(macOS 11.0, *)
Expand All @@ -30,8 +30,10 @@ struct Main {
static let keyIdentifier = ""
static let teamIdentifier = ""

private static let logger = Logger(label: "APNSwiftExample")

static func main() async throws {
let logger = Logger(subsystem: "apns", category: "apns-main")

let client = APNSClient(
configuration: .init(
authenticationMethod: .jwt(
Expand All @@ -55,14 +57,10 @@ struct Main {
try await Self.sendVoIP(with: client)
try await Self.sendFileProvider(with: client)
} catch {
logger.warning("error sending push:\(error)")
logger.warning("error sending push: \(error)")
}

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

Expand Down

0 comments on commit 25e1447

Please sign in to comment.