Files
FrenoCorp/node_modules/stream-json/utils/Batch.js
Michael Freno 7c684a42cc FRE-600: Fix code review blockers
- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 00:08:01 -04:00

45 lines
1.0 KiB
JavaScript

'use strict';
const {Transform} = require('stream');
const withParser = require('./withParser');
class Batch extends Transform {
static make(options) {
return new Batch(options);
}
static withParser(options) {
return withParser(Batch.make, options);
}
constructor(options) {
super(Object.assign({}, options, {writableObjectMode: true, readableObjectMode: true}));
this._batchSize = 1000;
if (options && typeof options.batchSize == 'number' && options.batchSize > 0) {
this._batchSize = options.batchSize;
}
this._accumulator = [];
}
_transform(chunk, _, callback) {
this._accumulator.push(chunk);
if (this._accumulator.length >= this._batchSize) {
this.push(this._accumulator);
this._accumulator = [];
}
callback(null);
}
_flush(callback) {
if (this._accumulator.length) {
this.push(this._accumulator);
this._accumulator = null;
}
callback(null);
}
}
Batch.batch = Batch.make;
Batch.make.Constructor = Batch;
module.exports = Batch;