Skip to content

Commit

Permalink
Update Swift Concurrency availability to include macOS 10.15, iOS 13.…
Browse files Browse the repository at this point in the history
…0 etc (#140)
  • Loading branch information
adam-fowler committed Aug 28, 2022
1 parent 3feb2ba commit 8a117a1
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-metrics.git", "1.0.0"..<"3.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.33.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "1.0.0-alpha.9"),
.package(url: "https://github.com/hummingbird-project/hummingbird-core.git", .upToNextMinor(from: "0.13.5")),
.package(url: "https://github.com/hummingbird-project/hummingbird-core.git", .upToNextMinor(from: "0.14.0")),
],
targets: [
.target(name: "Hummingbird", dependencies: [
Expand Down
8 changes: 4 additions & 4 deletions Sources/Hummingbird/AsyncAwaitSupport/AsyncMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import NIOCore

/// Middleware using async/await
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public protocol HBAsyncMiddleware: HBMiddleware {
func apply(to request: HBRequest, next: HBResponder) async throws -> HBResponse
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBAsyncMiddleware {
public func apply(to request: HBRequest, next: HBResponder) -> EventLoopFuture<HBResponse> {
let promise = request.eventLoop.makePromise(of: HBResponse.self)
Expand All @@ -33,7 +33,7 @@ extension HBAsyncMiddleware {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBResponder {
/// extend HBResponder to provide async/await version of respond
public func respond(to request: HBRequest) async throws -> HBResponse {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/AsyncAwaitSupport/AsyncResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import NIO

/// Responder that calls supplied closure
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public struct HBAsyncCallbackResponder: HBResponder {
let callback: (HBRequest) async throws -> HBResponse

Expand Down
14 changes: 7 additions & 7 deletions Sources/Hummingbird/AsyncAwaitSupport/ConnectionPool+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import Logging
import NIO

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBConnectionPool {
/// Request a connection, run a process and then release the connection
/// - Parameters:
Expand Down Expand Up @@ -48,7 +48,7 @@ extension HBConnectionPool {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBConnectionPoolGroup {
/// Request a connection, run a process and then release the connection
/// - Parameters:
Expand Down Expand Up @@ -80,12 +80,12 @@ extension HBConnectionPoolGroup {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public protocol HBAsyncConnection: HBConnection {
func close() async throws
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public extension HBAsyncConnection {
func close(on eventLoop: EventLoop) -> EventLoopFuture<Void> {
let promise = eventLoop.makePromise(of: Void.self)
Expand All @@ -96,12 +96,12 @@ public extension HBAsyncConnection {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public protocol HBAsyncConnectionSource: HBConnectionSource where Connection: HBAsyncConnection {
func makeConnection(on eventLoop: EventLoop, logger: Logger) async throws -> Connection
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public extension HBAsyncConnectionSource {
func makeConnection(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture<Connection> {
let promise = eventLoop.makePromise(of: Connection.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRequest.Persist {
/// Set value for key that will expire after a certain time.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

/// Route Handler using async/await methods
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public protocol HBAsyncRouteHandler: HBRouteHandler where _Output == EventLoopFuture<_Output2> {
associatedtype _Output2
init(from: HBRequest) throws
func handle(request: HBRequest) async throws -> _Output2
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBAsyncRouteHandler {
public func handle(request: HBRequest) throws -> EventLoopFuture<_Output2> {
let promise = request.eventLoop.makePromise(of: _Output2.self)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Hummingbird/AsyncAwaitSupport/Router+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import NIOCore

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRouterMethods {
/// GET path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func get<Output: HBResponseGenerator>(
Expand Down Expand Up @@ -92,7 +92,7 @@ extension HBRouterMethods {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRouter {
/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
Expand All @@ -107,7 +107,7 @@ extension HBRouter {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBRouterGroup {
/// Add path for closure returning type conforming to ResponseFutureEncodable
@discardableResult public func on<Output: HBResponseGenerator>(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/Router/RouterMethods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public protocol HBRouterMethods {
use: @escaping (HBRequest) -> EventLoopFuture<Output>
) -> Self

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)
/// Add path for async closure
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult func on<Output: HBResponseGenerator>(
_ path: String,
method: HTTPMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import Logging

/// Middleware using async/await
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBFileIO {
/// Load file and return response body
///
Expand Down
7 changes: 7 additions & 0 deletions Sources/HummingbirdFoundation/Files/FileIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,10 @@ public struct HBFileIO {
}
}
}

#if compiler(>=5.6)
// Can set this to @unchecked Sendable due to the way it is used. The `read`
// function that accesses the non-Sendable parts of the class is never
// called concurrently
extension HBFileIO.FileStreamer: @unchecked Sendable {}
#endif
6 changes: 3 additions & 3 deletions Sources/HummingbirdJobs/AsyncAwaitSupport/AsyncJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import NIOCore

/// Job with asynchronous handler
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public protocol HBAsyncJob: HBJob {
/// Execute job
func execute(logger: Logger) async throws
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBAsyncJob {
func execute(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture<Void> {
let promise = eventLoop.makePromise(of: Void.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import NIOCore

/// Job with asynchronous handler
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension HBJobQueue {
/// Push job onto queue
/// - Parameters:
Expand Down
4 changes: 2 additions & 2 deletions Tests/HummingbirdFoundationTests/FileTests+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import Foundation
import Hummingbird
import HummingbirdFoundation
import HummingbirdXCT
import XCTest

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
class HummingbirdAsyncFilesTests: XCTestCase {
func randomBuffer(size: Int) -> ByteBuffer {
var data = [UInt8](repeating: 0, count: size)
Expand Down
4 changes: 2 additions & 2 deletions Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ final class HummingbirdJobsTests: XCTestCase {
wait(for: [TestJob.expectation], timeout: 5)
}

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testAsyncJob() throws {
#if os(macOS)
// disable macOS tests in CI. GH Actions are currently running this when they shouldn't
Expand Down
4 changes: 2 additions & 2 deletions Tests/HummingbirdTests/AsyncAwaitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import Hummingbird
import HummingbirdXCT
import NIOHTTP1
import XCTest

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
final class AsyncAwaitTests: XCTestCase {
func randomBuffer(size: Int) -> ByteBuffer {
var data = [UInt8](repeating: 0, count: size)
Expand Down
4 changes: 2 additions & 2 deletions Tests/HummingbirdTests/PersistTests+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import Hummingbird
import XCTest

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
final class AsyncPersistTests: XCTestCase {
func createApplication() throws -> HBApplication {
let app = HBApplication(testing: .live)
Expand Down

0 comments on commit 8a117a1

Please sign in to comment.