Skip to content

Commit a00a498

Browse files
authored
IOS-1320 :: Feature :: Missing Async DataSource and Repository Wrapper (mobilejazz#53)
1 parent 0807587 commit a00a498

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Sources/Harmony/Data/DataSource/Async/AsyncDataSourceWrapper.swift

+32
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,35 @@ public class AsyncDeleteDataSourceWrapper<D>: AsyncDeleteDataSource where D: Del
6464
try await dataSource.delete(query).async()
6565
}
6666
}
67+
68+
// swiftlint:disable line_length
69+
@available(iOS 13.0.0, *)
70+
public class AsyncDataSourceWrapper<D, T>: AsyncGetDataSource, AsyncPutDataSource, AsyncDeleteDataSource where D: GetDataSource, D: PutDataSource, D: DeleteDataSource, D.T == T {
71+
private let dataSource: D
72+
73+
public init(_ dataSource: D) {
74+
self.dataSource = dataSource
75+
}
76+
77+
public func get(_ query: Query) async throws -> T {
78+
try await dataSource.get(query).async()
79+
}
80+
81+
public func getAll(_ query: Query) async throws -> [T] {
82+
try await dataSource.getAll(query).async()
83+
}
84+
85+
@discardableResult
86+
public func put(_ value: T?, in query: Query) async throws -> T {
87+
try await dataSource.put(value, in: query).async()
88+
}
89+
90+
@discardableResult
91+
public func putAll(_ array: [T], in query: Query) async throws -> [T] {
92+
try await dataSource.putAll(array, in: query).async()
93+
}
94+
95+
public func delete(_ query: Query) async throws {
96+
try await dataSource.delete(query).async()
97+
}
98+
}

Sources/Harmony/Data/Repository/Async/AsyncRepositoryWrapper.swift

+32
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,35 @@ public class AsyncDeleteRepositoryWrapper<R, T>: AsyncDeleteRepository where R:
6464
try await repository.delete(query, operation: operation).async()
6565
}
6666
}
67+
68+
@available(iOS 13.0.0, *)
69+
// swiftlint:disable line_length
70+
public class AsyncRepositoryWrapper<R, T>: AsyncGetRepository, AsyncPutRepository, AsyncDeleteRepository where R: GetRepository, R: PutRepository, R: DeleteRepository, R.T == T {
71+
private let repository: R
72+
73+
public init(_ repository: R) {
74+
self.repository = repository
75+
}
76+
77+
public func get(_ query: Query, operation: Operation) async throws -> T {
78+
try await repository.get(query, operation: operation).async()
79+
}
80+
81+
public func getAll(_ query: Query, operation: Operation) async throws -> [T] {
82+
try await repository.getAll(query, operation: operation).async()
83+
}
84+
85+
@discardableResult
86+
public func put(_ value: T?, in query: Query, operation: Operation) async throws -> T {
87+
try await repository.put(value, in: query, operation: operation).async()
88+
}
89+
90+
@discardableResult
91+
public func putAll(_ array: [T], in query: Query, operation: Operation) async throws -> [T] {
92+
try await repository.putAll(array, in: query, operation: operation).async()
93+
}
94+
95+
public func delete(_ query: Query, operation: Operation) async throws {
96+
try await repository.delete(query, operation: operation).async()
97+
}
98+
}

0 commit comments

Comments
 (0)