1.0.0 • Published 9 years ago

batchable v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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!
1.0.0

9 years ago