Repository URL to install this package:
|
Version:
5.0.0-1 ▾
|
vending-agent-dep
/
usr
/
local
/
lib
/
vending
/
agent
/
node_modules
/
native-promise-util
/
dist
/
each.js
|
|---|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.each = void 0;
const utils_1 = require("./utils");
async function each(input, iterator, options) {
var _a;
let maxInflight = (_a = options === null || options === void 0 ? void 0 : options.inflight) !== null && _a !== void 0 ? _a : 1;
if (maxInflight < 1) {
maxInflight = 1;
}
const resolvedInput = await input;
const inputLength = utils_1.getLength(resolvedInput);
const inputIterator = resolvedInput[Symbol.iterator]();
let iteratedCount = 0;
const inflights = [];
const output = [];
let nextItem = inputIterator.next();
if (maxInflight < 2) {
// Provides a higher performance implementation without push() and shift()
while (nextItem.done !== true) {
const index = iteratedCount;
iteratedCount++;
const resolvedItem = await nextItem.value;
await iterator(resolvedItem, index, inputLength);
output.push(resolvedItem);
nextItem = inputIterator.next();
}
}
else {
while (nextItem.done !== true) {
const index = iteratedCount;
iteratedCount++;
if (inflights.length >= maxInflight) {
await inflights.shift();
}
const resolvedItem = await nextItem.value;
inflights.push(iterator(resolvedItem, index, inputLength));
output.push(resolvedItem);
nextItem = inputIterator.next();
}
while (inflights.length > 0) {
await inflights.shift();
}
}
return output;
}
exports.each = each;