Skip to content

refactor: use standardized swift-async-algorithms #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
--format html \
--output-dir=.test-coverage
- name: Upload test coverage html
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-coverage-report
path: .test-coverage
Expand All @@ -68,4 +68,4 @@ jobs:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v3
- name: Test
run: swift test --parallel
run: swift test --parallel
16 changes: 8 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"pins" : [
{
"identity" : "async-collections",
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/adam-fowler/async-collections",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "726af96095a19df6b8053ddbaed0a727aa70ccb2",
"version" : "0.1.0"
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
"identity" : "swift-algorithms",
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms.git",
"location" : "https://github.com/apple/swift-async-algorithms.git",
"state" : {
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
"revision" : "4c3ea81f81f0a25d0470188459c6d4bf20cf2f97",
"version" : "1.0.3"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/adam-fowler/async-collections", from: "0.0.1"),
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
],
targets: [
Expand All @@ -27,7 +27,7 @@ let package = Package(
name: "AsyncDataLoader",
dependencies: [
.product(name: "Algorithms", package: "swift-algorithms"),
.product(name: "AsyncCollections", package: "async-collections"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
]
),
.testTarget(name: "DataLoaderTests", dependencies: ["DataLoader"]),
Expand Down
8 changes: 4 additions & 4 deletions Sources/AsyncDataLoader/DataLoader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Algorithms
import AsyncCollections
import AsyncAlgorithms

public enum DataLoaderValue<T: Sendable>: Sendable {
case success(T)
Expand Down Expand Up @@ -117,7 +117,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
return []
}

return try await keys.concurrentMap { try await self.load(key: $0) }
return try await Array(keys.async.map { try await self.load(key: $0) })
}

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