Fix concurrency warnings in Transport.
This commit is contained in:
parent
6053c58334
commit
46645f700a
@ -123,18 +123,18 @@ public protocol Transport: Sendable {
|
|||||||
@discardableResult
|
@discardableResult
|
||||||
func send(request: URLRequest) async throws -> (HTTPURLResponse, Data?)
|
func send(request: URLRequest) async throws -> (HTTPURLResponse, Data?)
|
||||||
|
|
||||||
func send(request: URLRequest, completion: @escaping (Result<(HTTPURLResponse, Data?), Error>) -> Void)
|
func send(request: URLRequest, completion: @escaping @Sendable (Result<(HTTPURLResponse, Data?), Error>) -> Void)
|
||||||
|
|
||||||
/// Sends URLRequest that doesn't require any result information.
|
/// Sends URLRequest that doesn't require any result information.
|
||||||
func send(request: URLRequest, method: String) async throws
|
func send(request: URLRequest, method: String) async throws
|
||||||
|
|
||||||
func send(request: URLRequest, method: String, completion: @escaping (Result<Void, Error>) -> Void)
|
func send(request: URLRequest, method: String, completion: @escaping @Sendable (Result<Void, Error>) -> Void)
|
||||||
|
|
||||||
/// Sends URLRequest with a data payload and returns the HTTP headers and the data payload.
|
/// Sends URLRequest with a data payload and returns the HTTP headers and the data payload.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func send(request: URLRequest, method: String, payload: Data) async throws -> (HTTPURLResponse, Data?)
|
func send(request: URLRequest, method: String, payload: Data) async throws -> (HTTPURLResponse, Data?)
|
||||||
|
|
||||||
func send(request: URLRequest, method: String, payload: Data, completion: @escaping (Result<(HTTPURLResponse, Data?), Error>) -> Void)
|
func send(request: URLRequest, method: String, payload: Data, completion: @escaping @Sendable (Result<(HTTPURLResponse, Data?), Error>) -> Void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ extension URLSession: Transport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func send(request: URLRequest, completion: @escaping (Result<(HTTPURLResponse, Data?), Error>) -> Void) {
|
public func send(request: URLRequest, completion: @escaping @Sendable (Result<(HTTPURLResponse, Data?), Error>) -> Void) {
|
||||||
let task = self.dataTask(with: request) { (data, response, error) in
|
let task = self.dataTask(with: request) { (data, response, error) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if let error = error {
|
if let error = error {
|
||||||
@ -198,7 +198,7 @@ extension URLSession: Transport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func send(request: URLRequest, method: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
public func send(request: URLRequest, method: String, completion: @escaping @Sendable (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
var sendRequest = request
|
var sendRequest = request
|
||||||
sendRequest.httpMethod = method
|
sendRequest.httpMethod = method
|
||||||
@ -238,7 +238,7 @@ extension URLSession: Transport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func send(request: URLRequest, method: String, payload: Data, completion: @escaping (Result<(HTTPURLResponse, Data?), Error>) -> Void) {
|
public func send(request: URLRequest, method: String, payload: Data, completion: @escaping @Sendable (Result<(HTTPURLResponse, Data?), Error>) -> Void) {
|
||||||
|
|
||||||
var sendRequest = request
|
var sendRequest = request
|
||||||
sendRequest.httpMethod = method
|
sendRequest.httpMethod = method
|
||||||
|
@ -10,7 +10,7 @@ import Foundation
|
|||||||
|
|
||||||
extension Transport {
|
extension Transport {
|
||||||
|
|
||||||
public func send<R: Decodable>(request: URLRequest, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) async throws -> (HTTPURLResponse, R?) {
|
public func send<R: Decodable & Sendable>(request: URLRequest, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) async throws -> (HTTPURLResponse, R?) {
|
||||||
|
|
||||||
try await withCheckedThrowingContinuation { continuation in
|
try await withCheckedThrowingContinuation { continuation in
|
||||||
self.send(request: request, resultType: resultType, dateDecoding: dateDecoding, keyDecoding: keyDecoding) { result in
|
self.send(request: request, resultType: resultType, dateDecoding: dateDecoding, keyDecoding: keyDecoding) { result in
|
||||||
@ -27,7 +27,7 @@ extension Transport {
|
|||||||
/**
|
/**
|
||||||
Sends an HTTP get and returns JSON object(s)
|
Sends an HTTP get and returns JSON object(s)
|
||||||
*/
|
*/
|
||||||
public func send<R: Decodable>(request: URLRequest, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, completion: @escaping (Result<(HTTPURLResponse, R?), Error>) -> Void) {
|
public func send<R: Decodable & Sendable>(request: URLRequest, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, completion: @escaping @Sendable (Result<(HTTPURLResponse, R?), Error>) -> Void) {
|
||||||
|
|
||||||
send(request: request) { result in
|
send(request: request) { result in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@ -69,7 +69,7 @@ extension Transport {
|
|||||||
/**
|
/**
|
||||||
Sends the specified HTTP method with a JSON payload.
|
Sends the specified HTTP method with a JSON payload.
|
||||||
*/
|
*/
|
||||||
public func send<P: Encodable>(request: URLRequest, method: String, payload: P, completion: @escaping (Result<Void, Error>) -> Void) {
|
public func send<P: Encodable>(request: URLRequest, method: String, payload: P, completion: @escaping @Sendable (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
var postRequest = request
|
var postRequest = request
|
||||||
postRequest.addValue("application/json; charset=utf-8", forHTTPHeaderField: HTTPRequestHeader.contentType)
|
postRequest.addValue("application/json; charset=utf-8", forHTTPHeaderField: HTTPRequestHeader.contentType)
|
||||||
@ -97,7 +97,7 @@ extension Transport {
|
|||||||
/**
|
/**
|
||||||
Sends the specified HTTP method with a JSON payload and returns JSON object(s).
|
Sends the specified HTTP method with a JSON payload and returns JSON object(s).
|
||||||
*/
|
*/
|
||||||
public func send<P: Encodable, R: Decodable>(request: URLRequest, method: String, payload: P, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, completion: @escaping (Result<(HTTPURLResponse, R?), Error>) -> Void) {
|
public func send<P: Encodable, R: Decodable>(request: URLRequest, method: String, payload: P, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, completion: @escaping @Sendable (Result<(HTTPURLResponse, R?), Error>) -> Void) {
|
||||||
|
|
||||||
var postRequest = request
|
var postRequest = request
|
||||||
postRequest.addValue("application/json; charset=utf-8", forHTTPHeaderField: HTTPRequestHeader.contentType)
|
postRequest.addValue("application/json; charset=utf-8", forHTTPHeaderField: HTTPRequestHeader.contentType)
|
||||||
@ -154,7 +154,7 @@ extension Transport {
|
|||||||
/**
|
/**
|
||||||
Sends the specified HTTP method with a Raw payload and returns JSON object(s).
|
Sends the specified HTTP method with a Raw payload and returns JSON object(s).
|
||||||
*/
|
*/
|
||||||
public func send<R: Decodable>(request: URLRequest, method: String, data: Data, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, completion: @escaping (Result<(HTTPURLResponse, R?), Error>) -> Void) {
|
public func send<R: Decodable>(request: URLRequest, method: String, data: Data, resultType: R.Type, dateDecoding: JSONDecoder.DateDecodingStrategy = .iso8601, keyDecoding: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, completion: @escaping @Sendable (Result<(HTTPURLResponse, R?), Error>) -> Void) {
|
||||||
|
|
||||||
send(request: request, method: method, payload: data) { result in
|
send(request: request, method: method, payload: data) { result in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user