batchable

1.0.0 • Public • Published

batchable

Handle consecutive function calls at once.

npm install batchable --save

Usage

import batchable from 'batchable';
 
// Batched function is called when current call stack has cleared.
let batchedGreet = batchable((calls) => {
  // calls is an array of arguments objects converted to array.
  let names = calls.map(c => c[0]);
  let last = names.pop();
 
  console.log(`Hello ${names.join('')} and ${last}!`);
 
  calls.forEach(c => c[1]());
});
 
function greet(name = 'stranger', callback = () => {}) {
  batchedHi(name, callback);
};
 
greet('Tim');
greet('Johnny');
greet('Peter', () => console.log('Peter has been greeted!'));
 
// -> Hello Tim, Johnny and Peter!
// -> Peter has been greeted!

Readme

Keywords

none

Package Sidebar

Install

npm i batchable

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • oliger