You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -37,7 +40,7 @@ final public class DataLoader<Key: Hashable, Value> {
37
40
publicfunc load(key:Key, on eventLoopGroup:EventLoopGroup)throws->EventLoopFuture<Value>{
38
41
letcacheKey= options.cacheKeyFunction?(key)?? key
39
42
40
-
returntrylock.withLock{
43
+
return lock.withLock{
41
44
if options.cachingEnabled,let cachedFuture =cache[cacheKey]{
42
45
return cachedFuture
43
46
}
@@ -53,16 +56,20 @@ final public class DataLoader<Key: Hashable, Value> {
53
56
dispatchScheduled =true
54
57
}
55
58
}else{
56
-
_ =trybatchLoadFunction([key]).map{ results in
57
-
if results.isEmpty {
58
-
promise.fail(DataLoaderError.noValueForKey("Did not return value for key: \(key)"))
59
-
}else{
60
-
letresult=results[0]
61
-
switch result {
62
-
case.success(let value): promise.succeed(value)
63
-
case.failure(let error): promise.fail(error)
59
+
do{
60
+
_ =trybatchLoadFunction([key]).map{ results in
61
+
if results.isEmpty {
62
+
promise.fail(DataLoaderError.noValueForKey("Did not return value for key: \(key)"))
63
+
}else{
64
+
letresult=results[0]
65
+
switch result {
66
+
case.success(let value): promise.succeed(value)
67
+
case.failure(let error): promise.fail(error)
68
+
}
64
69
}
65
70
}
71
+
}catch{
72
+
promise.fail(error)
66
73
}
67
74
}
68
75
@@ -181,20 +188,24 @@ final public class DataLoader<Key: Hashable, Value> {
181
188
182
189
// Step through the values, resolving or rejecting each Promise in the
183
190
// loaded queue.
184
-
_ =trybatchLoadFunction(keys).flatMapThrowing{ values in
185
-
if values.count != keys.count {
186
-
throwDataLoaderError.typeError("The function did not return an array of the same length as the array of keys. \nKeys count: \(keys.count)\nValues count: \(values.count)")
187
-
}
191
+
do{
192
+
_ =trybatchLoadFunction(keys).flatMapThrowing{ values in
193
+
if values.count != keys.count {
194
+
throwDataLoaderError.typeError("The function did not return an array of the same length as the array of keys. \nKeys count: \(keys.count)\nValues count: \(values.count)")
0 commit comments