Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.map = void 0;
const utils_1 = require("./utils");
async function buildMapExecWorker(context, mapper) {
    let nextResult = context.iterator.next();
    while (nextResult.done !== true) {
        const index = context.iteratedCount;
        context.iteratedCount++;
        const mapped = mapper(await nextResult.value, index, context.inputLength);
        context.output[index] = await mapped;
        nextResult = context.iterator.next();
    }
}
async function map(input, mapper, options) {
    var _a;
    let availableConcurrency = (_a = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _a !== void 0 ? _a : Infinity;
    if (availableConcurrency < 1) {
        availableConcurrency = 1;
    }
    const resolvedInput = await input;
    const context = {
        iterator: resolvedInput[Symbol.iterator](),
        inputLength: utils_1.getLength(resolvedInput),
        iteratedCount: 0,
        output: []
    };
    let availableInput = context.inputLength;
    const workers = [];
    while (availableConcurrency > 0 && availableInput > 0) {
        workers.push(buildMapExecWorker(context, mapper));
        availableInput--;
        availableConcurrency--;
    }
    await Promise.all(workers);
    return context.output;
}
exports.map = map;