Skip to content

Commit 8c0e119

Browse files
Make async/await internal API consistent
There were two API calls to same task for iOS 15 and pre iOS. Have made one to both cases.
1 parent 8398c5d commit 8c0e119

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

Sources/web3swift/Web3/Web3+HttpProvider.swift

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,11 @@ public class Web3HttpProvider: Web3Provider {
5858
}
5959

6060
fileprivate static func dataFrom(session: URLSession, request urlRequest: URLRequest) async throws -> Data{
61-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
62-
let (data, _) = try await session.data(for: urlRequest)
63-
return data
64-
} else {
65-
let (data, _) = try await session.data(forRequest: urlRequest)
66-
// Fallback on earlier versions
67-
return data
68-
}
61+
let (data, _) = try await session.data(for: urlRequest)
62+
return data
6963
}
7064

7165
static func post<T: Decodable, U: Encodable>(_ request: U, providerURL: URL, session: URLSession) async throws -> T {
72-
7366
let requestData = try JSONEncoder().encode(request)
7467
var urlRequest = URLRequest(url: providerURL, cachePolicy: .reloadIgnoringCacheData)
7568
urlRequest.httpMethod = "POST"
@@ -96,12 +89,14 @@ public class Web3HttpProvider: Web3Provider {
9689
return try await Web3HttpProvider.post(request, providerURL: self.url, session: self.session)
9790
}
9891

99-
public func sendAsync(_ requests: JSONRPCrequestBatch) async throws -> JSONRPCresponseBatch {
100-
return try await Web3HttpProvider.post(requests, providerURL: self.url, session: self.session)
101-
}
92+
// public func sendAsync(_ requests: JSONRPCrequestBatch) async throws -> JSONRPCresponseBatch {
93+
// return try await Web3HttpProvider.post(requests, providerURL: self.url, session: self.session)
94+
// }
10295
}
10396

97+
10498
@available(iOS, obsoleted: 15.0, message: "Use the built-in API instead")
99+
@available(macOS, obsoleted: 12.0, message: "Use the built-in API instead")
105100
extension URLSession {
106101
func data(fromUrl url: URL) async throws -> (Data, URLResponse) {
107102
try await withCheckedThrowingContinuation { continuation in
@@ -110,15 +105,13 @@ extension URLSession {
110105
let error = error ?? URLError(.badServerResponse)
111106
return continuation.resume(throwing: error)
112107
}
113-
114108
continuation.resume(returning: (data, response))
115109
}
116-
117110
task.resume()
118111
}
119112
}
120113

121-
func data(forRequest request: URLRequest) async throws -> (Data, URLResponse) {
114+
func data(for request: URLRequest) async throws -> (Data, URLResponse) {
122115
var dataTask: URLSessionDataTask?
123116

124117
return try await withCheckedThrowingContinuation { continuation in
@@ -127,10 +120,8 @@ extension URLSession {
127120
let error = error ?? URLError(.badServerResponse)
128121
return continuation.resume(throwing: error)
129122
}
130-
131123
continuation.resume(returning: (data, response))
132124
}
133-
134125
dataTask?.resume()
135126
}
136127
}

0 commit comments

Comments
 (0)