File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 11//
2- // CoreService .swift
2+ // HttpClient .swift
33// PersonalDictionary
44//
55// Created by Maxim Ivanov on 09.10.2021.
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments