"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cMap = void 0;
const pMap = require("p-map");
const event_loop_spinner_1 = require("event-loop-spinner");
/** Run a function each element in an array, with some level of concurrency.
 *
 * Defaults to a small, finite concurrency, so as to not to "overload" the database
 * connection pool or the http client, both of which have small, internal limits.
 *
 * Can be used with async functions that don't yield; will yield for you, if necessary.
 */
async function cMap(input, mapper, options) {
    var _a;
    const concurrency = (_a = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _a !== void 0 ? _a : 6;
    return await pMap(input, async (from) => {
        if (event_loop_spinner_1.eventLoopSpinner.isStarving()) {
            await event_loop_spinner_1.eventLoopSpinner.spin();
        }
        return await mapper(from);
    }, { concurrency });
}
exports.cMap = cMap;
//# sourceMappingURL=c-map.js.map