UNPKG

@bazilio-san/af-stream

Version:
34 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const AbstractSender_1 = require("./AbstractSender"); class CallbackSender extends AbstractSender_1.default { constructor(options) { super(options); const { eventCallback } = options.senderConfig; if (typeof eventCallback !== 'function') { options.exitOnError(`Missing event callback function when instantiating CallbackSender class`); } this.eventCallback = eventCallback; } async connect() { this.options.echo.info(`=================== Callback Sender is Ready ===================`); return true; } async sendEvents(recordsComposite) { const { eventsPacket } = recordsComposite; if (!eventsPacket.length) { return false; } const packet = eventsPacket.splice(0, eventsPacket.length); const pl = packet.length; recordsComposite.sentBufferLength = pl; recordsComposite.sendCount = pl; recordsComposite.last = packet[pl - 1]; packet.forEach((row) => { this.eventCallback(row); }); return true; } } exports.default = CallbackSender; //# sourceMappingURL=CallbackSender.js.map