Skip to content

Commit 2e00afa

Browse files
committed
Follow up to #18
1 parent 9b025ee commit 2e00afa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ export default class DataLoader<K, V> {
166166
var cacheKeyFn = this._options && this._options.cacheKeyFn;
167167
var cacheKey = cacheKeyFn ? cacheKeyFn(key) : key;
168168

169-
// Cache a rejected promise if the value is an Error, in order to match the
170-
// behavior of load(key).
171-
var promise = value instanceof Error ?
169+
// Only add the key if it does not already exist.
170+
if (this._promiseCache.get(cacheKey) === undefined) {
171+
// Cache a rejected promise if the value is an Error, in order to match
172+
// the behavior of load(key).
173+
var promise = value instanceof Error ?
172174
Promise.reject(value) :
173175
Promise.resolve(value);
174176

175-
// Only add the key if it does not already exist.
176-
if (this._promiseCache.get(cacheKey) === undefined) {
177177
this._promiseCache.set(cacheKey, promise);
178178
}
179179

0 commit comments

Comments
 (0)