stringbatcher
Version:
A string processing batcher by chunks decomposition and handling!
30 lines (29 loc) • 1.42 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
test('Batching working all right', () => __awaiter(void 0, void 0, void 0, function* () {
const testStr = 'ABCDEFGHIJKLMNOPQ';
const processStrs = [];
const batcher = new _1.StringBatcher({
batchSize: 3,
process: (str) => __awaiter(void 0, void 0, void 0, function* () {
processStrs.push(str);
})
});
yield batcher.process(testStr);
expect(processStrs[0]).toBe('ABC');
expect(processStrs[1]).toBe('DEF');
expect(processStrs[2]).toBe('GHI');
expect(processStrs[3]).toBe('JKL');
expect(processStrs[4]).toBe('MNO');
expect(processStrs[5]).toBe('PQ');
}));
;