Skip to content

Commit

Permalink
Add numerous missing @preconcurrency attributes (#3074)
Browse files Browse the repository at this point in the history
* Add numerous missing `@preconcurrency` attributes to various methods which accept `@Sendable` closure parameters but didn't always do so.
* Update Swift version badge in README
  • Loading branch information
gwynne committed Sep 28, 2023
1 parent 446b877 commit 036d67e
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<img src="https://github.com/vapor/vapor/actions/workflows/test.yml/badge.svg?branch=main" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="https://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6">
<img src="https://img.shields.io/badge/swift-5.7-brightgreen.svg" alt="Swift 5.7">
</a>
<a href="https://twitter.com/codevapor">
<img src="https://img.shields.io/badge/twitter-codevapor-5AA9E7.svg" alt="Twitter">
Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Cache/Application+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Application {
public struct Provider: Sendable {
let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand All @@ -46,7 +46,7 @@ extension Application {
provider.run(self.application)
}

public func use(_ makeCache: @Sendable @escaping (Application) -> (Cache)) {
@preconcurrency public func use(_ makeCache: @Sendable @escaping (Application) -> (Cache)) {
self.storage.makeCache.withLockedValue { $0 = .init(factory: makeCache) }
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Client/Application+Clients.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Application {
public struct Provider {
let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand All @@ -43,7 +43,7 @@ extension Application {
provider.run(self.application)
}

public func use(_ makeClient: @Sendable @escaping (Application) -> (Client)) {
@preconcurrency public func use(_ makeClient: @Sendable @escaping (Application) -> (Client)) {
self.storage.makeClient.withLockedValue { $0 = .init(factory: makeClient) }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/HTTP/BasicResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct BasicResponder: Responder {
///
/// - parameters:
/// - closure: Responder closure.
public init(
@preconcurrency public init(
closure: @Sendable @escaping (Request) throws -> EventLoopFuture<Response>
) {
self.closure = closure
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/HTTP/Server/HTTPServerUpgradeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public struct WebSocketUpgrader: Upgrader, Sendable {
var shouldUpgrade: (@Sendable () -> EventLoopFuture<HTTPHeaders?>)
var onUpgrade: @Sendable (WebSocket) -> ()

public init(maxFrameSize: WebSocketMaxFrameSize, shouldUpgrade: @escaping (@Sendable () -> EventLoopFuture<HTTPHeaders?>), onUpgrade: @Sendable @escaping (WebSocket) -> ()) {
@preconcurrency public init(maxFrameSize: WebSocketMaxFrameSize, shouldUpgrade: @escaping (@Sendable () -> EventLoopFuture<HTTPHeaders?>), onUpgrade: @Sendable @escaping (WebSocket) -> ()) {
self.maxFrameSize = maxFrameSize
self.shouldUpgrade = shouldUpgrade
self.onUpgrade = onUpgrade
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Middleware/ErrorMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class ErrorMiddleware: Middleware {
///
/// - parameters:
/// - closure: Error-handling closure. Converts `Error` to `Response`.
public init(_ closure: @Sendable @escaping (Request, Error) -> (Response)) {
@preconcurrency public init(_ closure: @Sendable @escaping (Request, Error) -> (Response)) {
self.closure = closure
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Passwords/Application+Passwords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension Application {
public struct Provider: Sendable {
let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand All @@ -24,7 +24,7 @@ extension Application {
provider.run(self.application)
}

public func use(
@preconcurrency public func use(
_ makeVerifier: @Sendable @escaping (Application) -> (PasswordHasher)
) {
self.storage.makeVerifier.withLockedValue { $0 = .init(factory: makeVerifier) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Request/Request+Body.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Request {
}
}

public func drain(_ handler: @Sendable @escaping (BodyStreamResult) -> EventLoopFuture<Void>) {
@preconcurrency public func drain(_ handler: @Sendable @escaping (BodyStreamResult) -> EventLoopFuture<Void>) {
switch self.request.bodyStorage {
case .stream(let stream):
stream.read { (result, promise) in
Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Responder/Application+Responder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Application {

let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ extension Application {
provider.run(self.application)
}

public func use(_ factory: @Sendable @escaping (Application) -> (Vapor.Responder)) {
@preconcurrency public func use(_ factory: @Sendable @escaping (Application) -> (Vapor.Responder)) {
self.storage.factory.withLockedValue { $0 = .init(factory: factory) }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Routing/Request+WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import WebSocketKit
import NIOHTTP1

extension Request {
public func webSocket(
@preconcurrency public func webSocket(
maxFrameSize: WebSocketMaxFrameSize = .`default`,
shouldUpgrade: @escaping (@Sendable (Request) -> EventLoopFuture<HTTPHeaders?>) = {
$0.eventLoop.makeSucceededFuture([:])
Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Server/Application+Servers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Application {
public struct Provider {
let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand Down Expand Up @@ -47,7 +47,7 @@ extension Application {
provider.run(self.application)
}

public func use(_ makeServer: @Sendable @escaping (Application) -> (Server)) {
@preconcurrency public func use(_ makeServer: @Sendable @escaping (Application) -> (Server)) {
self.storage.makeServer.withLockedValue { $0 = .init(factory: makeServer) }
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Sessions/Application+Sessions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Application {

let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand Down Expand Up @@ -71,7 +71,7 @@ extension Application {
provider.run(self.application)
}

public func use(_ makeDriver: @Sendable @escaping (Application) -> (SessionDriver)) {
@preconcurrency public func use(_ makeDriver: @Sendable @escaping (Application) -> (SessionDriver)) {
self.storage.makeDriver.withLockedValue { $0 = .init(factory: makeDriver) }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Sessions/SessionsConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct SessionsConfiguration: Sendable {
/// - parameters:
/// - cookieName: Name of HTTP cookie, used as a key for the cookie value.
/// - cookieFactory: Creates a new `HTTPCookieValue` for the supplied value `String`.
public init(cookieName: String, cookieFactory: @Sendable @escaping (SessionID) -> HTTPCookies.Value) {
@preconcurrency public init(cookieName: String, cookieFactory: @Sendable @escaping (SessionID) -> HTTPCookies.Value) {
self.cookieName = cookieName
self.cookieFactory = cookieFactory
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Utilities/FileIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public struct FileIO: Sendable {
/// - chunkSize: Maximum size for the file data chunks.
/// - onRead: Closure to be called sequentially for each file data chunk.
/// - returns: `Future` that will complete when the file read is finished.
public func readFile(
@preconcurrency public func readFile(
at path: String,
chunkSize: Int = NonBlockingFileIO.defaultChunkSize,
onRead: @Sendable @escaping (ByteBuffer) -> EventLoopFuture<Void>
Expand Down Expand Up @@ -122,7 +122,7 @@ public struct FileIO: Sendable {
/// - mediaType: HTTPMediaType, if not specified, will be created from file extension.
/// - onCompleted: Closure to be run on completion of stream.
/// - returns: A `200 OK` response containing the file stream and appropriate headers.
public func streamFile(
@preconcurrency public func streamFile(
at path: String,
chunkSize: Int = NonBlockingFileIO.defaultChunkSize,
mediaType: HTTPMediaType? = nil,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Utilities/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

extension Thread {
/// Convenience wrapper around `Thread.detachNewThread`.
public static func async(_ work: @Sendable @escaping () -> ()) {
@preconcurrency public static func async(_ work: @Sendable @escaping () -> ()) {
Thread.detachNewThread {
work()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Validation/Validations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct Validations: Sendable {
self.storage.append(.init(nested: key, required: required, keyed: validations, customFailureDescription: customFailureDescription))
}

public mutating func add(
@preconcurrency public mutating func add(
each key: ValidationKey,
required: Bool = true,
customFailureDescription: String? = nil,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vapor/Validation/Validator.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public struct Validator<T: Decodable & Sendable>: Sendable {
public let validate: @Sendable (_ data: T) -> ValidatorResult
public init(validate: @Sendable @escaping (_ data: T) -> ValidatorResult) {
@preconcurrency public init(validate: @Sendable @escaping (_ data: T) -> ValidatorResult) {
self.validate = validate
}
}
4 changes: 2 additions & 2 deletions Sources/Vapor/View/Application+Views.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Application {

let run: @Sendable (Application) -> ()

public init(_ run: @Sendable @escaping (Application) -> ()) {
@preconcurrency public init(_ run: @Sendable @escaping (Application) -> ()) {
self.run = run
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ extension Application {
provider.run(self.application)
}

public func use(_ makeRenderer: @Sendable @escaping (Application) -> (ViewRenderer)) {
@preconcurrency public func use(_ makeRenderer: @Sendable @escaping (Application) -> (ViewRenderer)) {
self.storage.makeRenderer.withLockedValue { $0 = .init(factory: makeRenderer) }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTVapor/XCTApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension Application {
try app.server.start(address: .hostname(self.hostname, port: self.port))
defer { app.server.shutdown() }

let client = HTTPClient(eventLoopGroupProvider: .createNew)
let client = HTTPClient(eventLoopGroup: NIOSingletons.posixEventLoopGroup)
defer { try! client.syncShutdown() }
var path = request.url.path
path = path.hasPrefix("/") ? path : "/\(path)"
Expand Down

0 comments on commit 036d67e

Please sign in to comment.