Skip to content

Commit 2a8a5ed

Browse files
committed
release-2.3.0
1 parent fbe9256 commit 2a8a5ed

4 files changed

Lines changed: 79 additions & 1 deletion

File tree

Source/Array+Core.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,18 @@ extension Array {
1515
return self[index]
1616
}
1717
}
18+
19+
extension Array where Element: Hashable {
20+
21+
public func removingDuplicates() -> [Element] {
22+
var addedDict = [Element: Bool]()
23+
24+
return filter {
25+
addedDict.updateValue(true, forKey: $0) == nil
26+
}
27+
}
28+
29+
public mutating func removeDuplicates() {
30+
self = self.removingDuplicates()
31+
}
32+
}

Source/Networking/HttpClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// CoreService.swift
2+
// HttpClient.swift
33
// PersonalDictionary
44
//
55
// Created by Maxim Ivanov on 09.10.2021.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// HttpClientAdapter.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 21.05.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct HttpResponseResult {
11+
public let response: HTTPURLResponse
12+
public let data: Data
13+
14+
public init(response: HTTPURLResponse, data: Data) {
15+
self.response = response
16+
self.data = data
17+
}
18+
}
19+
20+
public protocol HttpClientAdapter {
21+
22+
func send(_ http: Http) async throws -> HttpResponseResult
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// HttpClientAdapter.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 21.05.2023.
6+
//
7+
8+
import Combine
9+
10+
public final class HttpClientAdapterImpl: HttpClientAdapter {
11+
12+
private let httpClient: HttpClient
13+
14+
private var cancellables: Set<AnyCancellable> = []
15+
16+
public init(httpClient: HttpClient = LoggableHttpClient(logger: LoggerImpl(category: "HTTP"))) {
17+
self.httpClient = httpClient
18+
}
19+
20+
public func send(_ http: Http) async throws -> HttpResponseResult {
21+
try await withCheckedThrowingContinuation { continuation in
22+
httpClient.send(http)
23+
.sink(
24+
receiveCompletion: { completion in
25+
switch completion {
26+
case .failure(let error):
27+
continuation.resume(throwing: error)
28+
case .finished:
29+
break
30+
}
31+
},
32+
receiveValue: { httpResponse in
33+
continuation.resume(
34+
returning: HttpResponseResult(response: httpResponse.response, data: httpResponse.data)
35+
)
36+
}
37+
).store(in: &self.cancellables)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)