export interface ItemBufferParams < Item > { /**
     * Flushes buffer automatically if number of items in the buffer reaches
     * this number. Omit it or set to `Infinity` to never flush on max buffer
     * size automatically.
     */ flushOnMaxItems ? : number ; /**
     * Callback that is called every time buffer is flushed. It receives a single
     * argument which is a list of all buffered items. If `.flush()` is called
     * when buffer is empty, `.onflush` is called with empty array.
     */ onFlush : ( items : Item [ ] ) => void ; } /**
 * A simple buffer that collects items. Can be cleared or flushed; and can
 * automatically flush when specified number of items is reached.
 */ export class ItemBuffer < Item > { private list : Item [ ] = [ ] ; constructor ( public readonly params ) { } /**
     * Get current buffer size.
     */ public get length ( ) : number { return this . list . length ; } /**
     * Add item to the buffer.
     */ public write ( item ) { this . list . push ( item ) ; const { flushOnMaxItems } = this . params ; if ( flushOnMaxItems ) { if ( this . list . length >= flushOnMaxItems ) { this . flush ( ) ; } } } /**
     * Remove all items from the buffer.
     */ public clear ( ) { this . list = [ ] ; } /**
     * Call `.onflush` method and clear buffer.
     */ public flush ( ) { let list ; [ list , this . list ] = [ this . list , [ ] ] ; this . params . onFlush ( list ) ; } }