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

Updating project for strict concurrency and Swift 6 #207

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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: swiftlang/swift:nightly-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: swiftlang/swift:nightly-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: swiftlang/swift:nightly-6.0-focal
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down
24 changes: 21 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:6.0
import PackageDescription

let package = Package(
Expand Down Expand Up @@ -31,17 +31,26 @@ let package = Package(
dependencies: [
.target(name: "APNSCore"),
.target(name: "APNS"),
]),
.product(name: "Logging", package: "swift-log"),
]
),
.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 +59,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 +74,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
21 changes: 3 additions & 18 deletions Sources/APNS/APNSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +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.
@preconcurrency 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()
/// Shuts down the client and event loop gracefully.
public func shutdown() async throws {
try await self.httpClient.shutdown()
}
}

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() async throws
}
29 changes: 19 additions & 10 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 Logging
import Foundation

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

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

static func main() async throws {

let client = APNSClient(
configuration: .init(
authenticationMethod: .jwt(
Expand All @@ -44,16 +48,21 @@ 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)
try await Self.sendPushToTalk(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)
try await Self.sendPushToTalk(with: client)
} catch {
logger.warning("error sending push: \(error)")
}

try? await client.shutdown()
}
}

Expand Down
Loading