-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt Sendable throughout API to support -strict-concurrency=complete (…
…#22) ### Motivation When using `-strict-concurrency=targeted`, `ClientMiddleware` will emit warnings if an actor is conformed to it: ```swift import OpenAPIRuntime import Foundation actor Middleware: ClientMiddleware { func intercept( _ request: Request, baseURL: URL, operationID: String, /// Need to add `@Sendable` or the warnings don't go away even with this PR. Code-completion won't add it. next: @sendable (Request, URL) async throws -> Response ) async throws -> Response { try await next(request, baseURL) } } ``` The `intercept` function will emit the following warning with the current implementation: > Sendability of function types in instance method 'intercept(_:baseURL:operationID:next:)' does not match requirement in protocol 'ClientMiddleware' Repro package: https://github.com/MahdiBM/OAPIRClientWarningsRepro You can change between this PR and the main branch by commenting out the dependency declarations i've already put in the `Package.swift`. Then observe there are no warnings with this PR, unlike with the main branch. ### Modifications Generally adopt Sendable throughout the whole API to support -strict-concurrency=complete. For the most part, this means using @sendable for closures, and using `any Sendable` instead of `Any`. As an example for closures, currently we have: ```swift public protocol ClientMiddleware: Sendable { func intercept( _ request: Request, baseURL: URL, operationID: String, next: (Request, URL) async throws -> Response ) async throws -> Response } ``` With this PR we'll have: ```swift public protocol ClientMiddleware: Sendable { func intercept( _ request: Request, baseURL: URL, operationID: String, next: @sendable (Request, URL) async throws -> Response /// ~~~^ notice `@Sendable` ) async throws -> Response } ``` ### Result Safer Sendable code + being more ready for Swift 6 + no more warnings when using `-strict-concurrency=targeted` then conforming an actor to `ClientMiddleware`. ### Test Plan Adopted all tests to the changes and added the strict-concurrency flag to CI. --------- Co-authored-by: Si Beaumont <[email protected]> Co-authored-by: Si Beaumont <[email protected]>
- Loading branch information
1 parent
fbd56ae
commit 45b2420
Showing
14 changed files
with
76 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters