diff --git a/Sources/DataLoader/DataLoader.swift b/Sources/DataLoader/DataLoader.swift index 5b457b4..d67e3c4 100644 --- a/Sources/DataLoader/DataLoader.swift +++ b/Sources/DataLoader/DataLoader.swift @@ -94,24 +94,8 @@ final public class DataLoader { guard !keys.isEmpty else { return eventLoopGroup.next().makeSucceededFuture([]) } - - let promise: EventLoopPromise<[Value]> = eventLoopGroup.next().makePromise() - - var result = [Value]() - let futures = try keys.map { try load(key: $0, on: eventLoopGroup) } - - for future in futures { - _ = future.map { value in - result.append(value) - - if result.count == keys.count { - promise.succeed(result) - } - } - } - - return promise.futureResult + return EventLoopFuture.whenAllSucceed(futures, on: eventLoopGroup.next()) } /// Clears the value at `key` from the cache, if it exists. Returns itself for