@botonic/plugin-contentful
Version:
Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet
52 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.reduceMultiError = exports.asyncEach = exports.resumable = exports.asyncMap = void 0;
const tslib_1 = require("tslib");
const Parallel = tslib_1.__importStar(require("async-parallel"));
const async_parallel_1 = require("async-parallel");
/**
* async-parallel makes code simpler and allows limiting concurrency
*/
function asyncMap(context, list, action, concurrency, errorTreatment) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield Parallel.map(list, resumable(action, errorTreatment), concurrency || context.concurrency);
return result.filter((i) => i !== undefined);
});
}
exports.asyncMap = asyncMap;
function resumable(action, errorTreatment) {
const wrapped = (value, index, list) => tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
return yield action(value, index, list);
}
catch (e) {
if (errorTreatment) {
return errorTreatment(value, e);
}
throw e;
}
});
return wrapped;
}
exports.resumable = resumable;
function asyncEach(context, list, action, concurrency) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
concurrency = concurrency || context.concurrency;
yield Parallel.each(list, action, concurrency);
});
}
exports.asyncEach = asyncEach;
function reduceMultiError(error) {
let reduced = [];
for (const e of error.list) {
if (e instanceof async_parallel_1.MultiError) {
reduced = reduced.concat(reduceMultiError(e));
}
else {
reduced.push(e);
}
}
return reduced;
}
exports.reduceMultiError = reduceMultiError;
//# sourceMappingURL=async.js.map