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
/// Clears the value at `key` from the cache, if it exists. Returns itself for
130
116
/// method chaining.
131
117
@discardableResult
132
118
publicfunc clear(key:Key)->DataLoader<Key,Value>{
133
119
letcacheKey= options.cacheKeyFunction?(key)?? key
120
+
134
121
cache.removeValue(forKey: cacheKey)
122
+
135
123
returnself
136
124
}
137
125
@@ -141,6 +129,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
141
129
@discardableResult
142
130
publicfunc clearAll()->DataLoader<Key,Value>{
143
131
cache.removeAll()
132
+
144
133
returnself
145
134
}
146
135
@@ -152,8 +141,9 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
152
141
153
142
ifcache[cacheKey]==nil{
154
143
letchannel=Channel<Value,Error>()
144
+
155
145
Task.detached{
156
-
await channel.fulfill(with:value)
146
+
await channel.fulfill(value)
157
147
}
158
148
159
149
cache[cacheKey]= channel
@@ -165,7 +155,9 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
165
155
publicfunc execute()asyncthrows{
166
156
// Take the current loader queue, replacing it with an empty queue.
167
157
letbatch= queue
158
+
168
159
queue =[]
160
+
169
161
if dispatchScheduled {
170
162
dispatchScheduled =false
171
163
}
@@ -196,6 +188,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
196
188
// loaded queue.
197
189
do{
198
190
letvalues=tryawaitbatchLoadFunction(keys)
191
+
199
192
if values.count != keys.count {
200
193
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)")
201
194
}
@@ -205,9 +198,9 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
205
198
206
199
switch result {
207
200
caselet.failure(error):
208
-
await entry.element.channel.fail(with:error)
201
+
await entry.element.channel.fail(error)
209
202
caselet.success(value):
210
-
await entry.element.channel.fulfill(with:value)
203
+
await entry.element.channel.fulfill(value)
211
204
}
212
205
}
213
206
}catch{
@@ -218,85 +211,8 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
0 commit comments