serverless-offline-msk
Version:
A serverless offline plugin that enables AWS MSK events
21 lines (16 loc) • 545 B
JavaScript
;
const pReflect = require('p-reflect');
const pLimit = require('p-limit');
module.exports = async (array, options = {}) => {
const {concurrency = Infinity} = options;
const limit = pLimit(concurrency);
return Promise.all(array.map(element => {
if (element && typeof element.then === 'function') { // eslint-disable-line promise/prefer-await-to-then
return pReflect(element);
}
if (typeof element === 'function') {
return pReflect(limit(() => element()));
}
return pReflect(Promise.resolve(element));
}));
};