"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * A more composable version of https://www.npmjs.com/package/promise-inflight.
 *
 * @param {Function}
 *        A unary, promise-returning function.
 * @returns {Function}
 *        A version of the given function which batches together calls for the
 *        the same input value.
 */
function batchConcurrent(fn) {
    const pendingCalls = new Map();
    return function wrapped(key) {
        if (pendingCalls.has(key)) {
            return pendingCalls.get(key);
        }
        const p = fn(key).finally(() => pendingCalls.delete(key));
        pendingCalls.set(key, p);
        return p;
    };
}
exports.default = batchConcurrent;
