(chunk: Buffer)
| 57 | } |
| 58 | |
| 59 | write(chunk: Buffer) { |
| 60 | if (this.data.length + chunk.length >= BATCH_MAX_SIZE) { |
| 61 | // We've reached the max batch size. Flush it and start another one |
| 62 | if (this.timeout) { |
| 63 | clearTimeout(this.timeout); |
| 64 | this.timeout = null; |
| 65 | } |
| 66 | this.flush(); |
| 67 | } |
| 68 | |
| 69 | this.data += this.decoder.write(chunk); |
| 70 | |
| 71 | if (!this.timeout) { |
| 72 | this.timeout = setTimeout(() => this.flush(), BATCH_DURATION_MS); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | flush() { |
| 77 | // Reset before emitting to allow for potential reentrancy |