Skip to content

Commit

Permalink
use forEachBail from enhanced-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jan 10, 2022
1 parent 9c6557e commit b54f2ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
19 changes: 2 additions & 17 deletions lib/CacheFacade.js
Expand Up @@ -5,6 +5,7 @@

"use strict";

const { forEachBail } = require("enhanced-resolve");
const asyncLib = require("neo-async");
const getLazyHashedEtag = require("./cache/getLazyHashedEtag");
const mergeEtags = require("./cache/mergeEtags");
Expand Down Expand Up @@ -46,23 +47,7 @@ class MultiItemCache {
* @returns {void}
*/
get(callback) {
let i = 0;
let resultFound = false;
const generateGetCallback = (/** @type {Boolean} */ lastItem) => {
return (
/** @type {import("./WebpackError")} */ err,
/** @type {T} */ res
) => {
if (resultFound) return;
resultFound = !!(err || res || false);
if (err) return callback(err);
if (res !== undefined) return callback(null, res);
if (lastItem) return callback();
};
};
do {
this._items[i].get(generateGetCallback(i === this._items.length - 1));
} while (++i < this._items.length);
forEachBail(this._items, (item, callback) => item.get(callback), callback);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/MultiItemCache.unittest.js
Expand Up @@ -32,7 +32,7 @@ describe("MultiItemCache", () => {
const multiItemCache = new MultiItemCache(itemCaches);
let callbacks = 0;
const callback = (err, res) => {
expect(err).toBeUndefined();
expect(err).toBeNull();
expect(res).toBeUndefined();
++callbacks;
};
Expand Down

0 comments on commit b54f2ac

Please sign in to comment.