From 12b481e10848a6da6c0a6ad37b2bd0b1c87ea941 Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Sat, 18 Apr 2026 10:25:10 -0600 Subject: [PATCH] chore: Remove AsyncCollections dependency --- Benchmarks/Package.resolved | 12 ++---------- Package.resolved | 11 +---------- Package.swift | 2 -- Sources/AsyncDataLoader/DataLoader.swift | 17 ++++++++++++++--- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Benchmarks/Package.resolved b/Benchmarks/Package.resolved index ff8ee56..e66137d 100644 --- a/Benchmarks/Package.resolved +++ b/Benchmarks/Package.resolved @@ -1,14 +1,6 @@ { + "originHash" : "291df3327aad87228cf28f3cc39ec8b92e332c285db9b81b29cb92cb71d46837", "pins" : [ - { - "identity" : "async-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/adam-fowler/async-collections", - "state" : { - "revision" : "726af96095a19df6b8053ddbaed0a727aa70ccb2", - "version" : "0.1.0" - } - }, { "identity" : "hdrhistogram-swift", "kind" : "remoteSourceControl", @@ -109,5 +101,5 @@ } } ], - "version" : 2 + "version" : 3 } diff --git a/Package.resolved b/Package.resolved index 1c1dc60..db677ca 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,15 +1,6 @@ { - "originHash" : "34ed11cdeebef1b2864a6db79a150ffe000d97cca7e36c30e30939d14f609619", + "originHash" : "cd234e013443e6dda35a41eb3c534540f5fa8abb6b1146f8037e768f237caa39", "pins" : [ - { - "identity" : "async-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/adam-fowler/async-collections", - "state" : { - "revision" : "726af96095a19df6b8053ddbaed0a727aa70ccb2", - "version" : "0.1.0" - } - }, { "identity" : "swift-algorithms", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 67bd8e7..92b2b32 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,6 @@ 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-nio.git", from: "2.84.0"), ], targets: [ @@ -27,7 +26,6 @@ let package = Package( name: "AsyncDataLoader", dependencies: [ .product(name: "Algorithms", package: "swift-algorithms"), - .product(name: "AsyncCollections", package: "async-collections"), ] ), .testTarget( diff --git a/Sources/AsyncDataLoader/DataLoader.swift b/Sources/AsyncDataLoader/DataLoader.swift index cd84750..705168a 100644 --- a/Sources/AsyncDataLoader/DataLoader.swift +++ b/Sources/AsyncDataLoader/DataLoader.swift @@ -1,5 +1,4 @@ import Algorithms -import AsyncCollections public enum DataLoaderValue: Sendable { case success(T) @@ -115,7 +114,19 @@ public actor DataLoader { return [] } - return try await keys.concurrentMap { try await self.load(key: $0) } + // This buffer pointer allows us to initialize a pre-sized non-nullable list + // that we can populate by index as `load` results stream in asyncronously + let buffer = UnsafeMutableBufferPointer.allocate(capacity: keys.count) + try await withThrowingTaskGroup { group in + for (index, element) in keys.enumerated() { + group.addTask { + let result = try await self.load(key: element) + buffer[index] = result + } + } + try await group.waitForAll() + } + return Array(buffer) } /// Clears the value at `key` from the cache, if it exists. Returns itself for @@ -175,7 +186,7 @@ public actor DataLoader { // 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 + for slicedBatch in batch.chunks(ofCount: maxBatchSize) { try await self.executeBatch(batch: Array(slicedBatch)) } } else {