-
Notifications
You must be signed in to change notification settings - Fork 33
Fix strict concurrency warnings #58
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9ad6a85
Initial work to resolve strict concurrency warnings
kevin-kp 3f021e6
Merge branch 'main' into chore/strict-concurrency
kevin-kp 2c2fbeb
Make Provider sendable and remove last warnings
kevin-kp 077537d
Fix concurrency issues in tests
kevin-kp c086900
Add method to add an interceptor
kevin-kp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,38 @@ | ||
| enum Coders { | ||
|
|
||
| // MARK: HTTP Body | ||
|
|
||
| static var defaultHTTPBodyEncoder: HTTPBodyEncoder = .json() | ||
| static var defaultHTTPBodyDecoder: HTTPBodyDecoder = .json() | ||
| static let defaultHTTPBodyEncoder: HTTPBodyEncoder = .json() | ||
| static let defaultHTTPBodyDecoder: HTTPBodyDecoder = .json() | ||
|
|
||
| // MARK: Query | ||
|
|
||
| static var defaultQueryEncoder = URLEncodedFormEncoder() | ||
| static var defaultQueryDecoder = URLEncodedFormDecoder() | ||
| static let defaultQueryEncoder = URLEncodedFormEncoder() | ||
| static let defaultQueryDecoder = URLEncodedFormDecoder() | ||
| } | ||
|
|
||
| public protocol CoderProvider: Sendable { | ||
| func provideHttpBodyEncoder() -> HTTPBodyEncoder | ||
| func provideHttpBodyDecoder() -> HTTPBodyDecoder | ||
| func provideQueryEncoder() -> URLEncodedFormEncoder | ||
| func provideQueryDecoder() -> URLEncodedFormDecoder | ||
| } | ||
|
|
||
| public struct DefaultProvider: CoderProvider { | ||
| public init() {} | ||
|
|
||
| public func provideHttpBodyEncoder() -> HTTPBodyEncoder { | ||
| return .json() | ||
| } | ||
|
|
||
| public func provideHttpBodyDecoder() -> HTTPBodyDecoder { | ||
| return .json() | ||
| } | ||
|
|
||
| public func provideQueryEncoder() -> URLEncodedFormEncoder { | ||
| return URLEncodedFormEncoder() | ||
| } | ||
|
|
||
| public func provideQueryDecoder() -> URLEncodedFormDecoder { | ||
| return URLEncodedFormDecoder() | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import Foundation | ||
|
|
||
| /// A type that can perform arbitrary HTTP requests. | ||
| public protocol HTTPService { | ||
| public protocol HTTPService: Sendable { | ||
| /// Build a `Request` from the given components. | ||
| func build(method: String, url: URL, headers: [String: String], body: Data?) -> PapyrusRequest | ||
|
|
||
| /// Concurrency based API | ||
| @Sendable | ||
| func request(_ req: PapyrusRequest) async -> PapyrusResponse | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // ResourceMutex.swift | ||
| // | ||
| // | ||
| // Created by Kevin Pittevils on 11/07/2024. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| // Note: Can be replaced with Synchronization framework starting with iOS 18. | ||
| final class ResourceMutex<R>: @unchecked Sendable { | ||
| private var resource: R | ||
| private let mutex: UnsafeMutablePointer<pthread_mutex_t> | ||
|
|
||
| init(resource: R) { | ||
| let mutexAttr = UnsafeMutablePointer<pthread_mutexattr_t>.allocate(capacity: 1) | ||
| pthread_mutexattr_init(mutexAttr) | ||
| pthread_mutexattr_settype(mutexAttr, Int32(PTHREAD_MUTEX_RECURSIVE)) | ||
| mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1) | ||
| pthread_mutex_init(mutex, mutexAttr) | ||
| pthread_mutexattr_destroy(mutexAttr) | ||
| mutexAttr.deallocate() | ||
| self.resource = resource | ||
| } | ||
|
|
||
| deinit { | ||
| pthread_mutex_destroy(mutex) | ||
| mutex.deallocate() | ||
| } | ||
|
|
||
| func withLock<T>(method: (inout R) throws -> T) throws -> T { | ||
| defer { unlock() } | ||
| lock() | ||
| return try method(&resource) | ||
| } | ||
|
|
||
| func withLock<T>(method: (inout R) -> T) -> T { | ||
| defer { unlock() } | ||
| lock() | ||
| return method(&resource) | ||
| } | ||
| } | ||
|
|
||
| private extension ResourceMutex { | ||
| func lock() { | ||
| pthread_mutex_lock(mutex) | ||
| } | ||
|
|
||
| func unlock() { | ||
| pthread_mutex_unlock(mutex) | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.