patrolling
Patrol buffers and flush, periodically or when the buffer is full.
Installation
npm install patrolling
Usage
import Patrolling from 'patrolling';
var patrolling = new Patrolling( capacity, timeout, flush, push );
Example
const buffer = [];
const capacity = 10;
const timeout = 100;
const flush = function() { buffer = []; console.log( 'flushed' ); }
const push = function( elem ) { buffer.push( elem ); }
const cache = new Patrolling( capacity, timeout, flush, push );
for ( var i = 0; i < 15; ++i ) {
cache.push( i );
}
cache.flush();
License
MIT. See LICENSE.md for details.