caminho
Version:
Tool for creating efficient data pipelines in a JavaScript environment
44 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.batch = batch;
exports.valueBagGetterBatchNoProvides = valueBagGetterBatchNoProvides;
exports.valueBagGetterBatchProvides = valueBagGetterBatchProvides;
const rxjs_1 = require("rxjs");
const valueBag_1 = require("../utils/valueBag");
function batch(params, loggers) {
const getBag = params.provides
? valueBagGetterBatchProvides(params.provides)
: valueBagGetterBatchNoProvides();
async function wrappedStep(valueBag) {
loggers.onStepStarted(valueBag);
const startTime = new Date();
try {
const values = await params.fn([...valueBag]);
const newValueBags = getBag(valueBag, values);
loggers.onStepFinished(newValueBags, startTime);
return newValueBags;
}
catch (err) {
loggers.onStepFinished(valueBag, startTime, err);
throw err;
}
}
return function operatorApplier(observable) {
return observable
.pipe((0, rxjs_1.bufferTime)(params.batch.timeoutMs, undefined, params.batch.maxSize))
.pipe((0, rxjs_1.filter)((buffer) => buffer.length > 0))
.pipe((0, rxjs_1.mergeMap)(wrappedStep, params.maxConcurrency))
.pipe((0, rxjs_1.mergeAll)());
};
}
function valueBagGetterBatchNoProvides() {
return function getValueBag(valueBag) {
return valueBag;
};
}
function valueBagGetterBatchProvides(provides) {
return function getValueBagWithProvides(valueBags, values) {
return valueBags.map((valueBag, index) => (0, valueBag_1.getNewValueBag)(valueBag, provides, values[index]));
};
}
//# sourceMappingURL=batch.js.map