Skip to content

Commit e4ac5f4

Browse files
Stabalizes loadMany by using NIO whenAllSucceed
Previously it could cause race conditions because of concurrent array access
1 parent fcaac97 commit e4ac5f4

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

Sources/DataLoader/DataLoader.swift

+1-17
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,8 @@ final public class DataLoader<Key: Hashable, Value> {
9494
guard !keys.isEmpty else {
9595
return eventLoopGroup.next().makeSucceededFuture([])
9696
}
97-
98-
let promise: EventLoopPromise<[Value]> = eventLoopGroup.next().makePromise()
99-
100-
var result = [Value]()
101-
10297
let futures = try keys.map { try load(key: $0, on: eventLoopGroup) }
103-
104-
for future in futures {
105-
_ = future.map { value in
106-
result.append(value)
107-
108-
if result.count == keys.count {
109-
promise.succeed(result)
110-
}
111-
}
112-
}
113-
114-
return promise.futureResult
98+
return EventLoopFuture.whenAllSucceed(futures, on: eventLoopGroup.next())
11599
}
116100

117101
/// Clears the value at `key` from the cache, if it exists. Returns itself for

0 commit comments

Comments
 (0)