Skip to content

Commit e8232e8

Browse files
committed
refactor: use standardized swift-async-algorithms
Adopts the more common (now-a-days) swift-async-algorithms for the simple async collection needs of this package. Helps adopt the standardized ecosystem where many other packages use swift-async-algorithms.
1 parent 52b1f3d commit e8232e8

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Package.resolved

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
],
1313
dependencies: [
1414
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
15-
.package(url: "https://github.com/adam-fowler/async-collections", from: "0.0.1"),
15+
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0"),
1616
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
1717
],
1818
targets: [
@@ -27,7 +27,7 @@ let package = Package(
2727
name: "AsyncDataLoader",
2828
dependencies: [
2929
.product(name: "Algorithms", package: "swift-algorithms"),
30-
.product(name: "AsyncCollections", package: "async-collections"),
30+
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
3131
]
3232
),
3333
.testTarget(name: "DataLoaderTests", dependencies: ["DataLoader"]),

Sources/AsyncDataLoader/DataLoader.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Algorithms
2-
import AsyncCollections
2+
import AsyncAlgorithms
33

44
public enum DataLoaderValue<T: Sendable>: Sendable {
55
case success(T)
@@ -117,7 +117,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
117117
return []
118118
}
119119

120-
return try await keys.concurrentMap { try await self.load(key: $0) }
120+
return try await Array(keys.async.map { try await self.load(key: $0) })
121121
}
122122

123123
/// Clears the value at `key` from the cache, if it exists. Returns itself for
@@ -177,8 +177,8 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
177177
// If a maxBatchSize was provided and the queue is longer, then segment the
178178
// queue into multiple batches, otherwise treat the queue as a single batch.
179179
if let maxBatchSize = options.maxBatchSize, maxBatchSize > 0, maxBatchSize < batch.count {
180-
try await batch.chunks(ofCount: maxBatchSize).asyncForEach { slicedBatch in
181-
try await self.executeBatch(batch: Array(slicedBatch))
180+
for try await slicedBatch in batch.chunks(ofCount: maxBatchSize).async {
181+
try await executeBatch(batch: Array(slicedBatch))
182182
}
183183
} else {
184184
try await executeBatch(batch: batch)

0 commit comments

Comments
 (0)