批处理
批处理项目并在批处理达到指定大小时执行操作
例子
const Batch = require ( 'batch-action' ) ;
function printMessage ( items ) {
console . log ( `Received batch with ${ items . length } item(s)` ) ;
}
const batch = new Batch ( {
size : 3 , // the action will be invoked every time 3 items are added
action : printMessage ,
} ) ;
batch . add ( 'a' ) ;
batch . add ( 'b' ) ;
batch . add ( 143 ) ;
// Action gets invoked w