Last Updated: February 25, 2016
·
472
· aintaer

Leaky Functional Bucket

To combine multiple calls to one function into one call (after all others are finished), use setTimeout to break out of the current call stack!

function collector() {
  collector._count = collector._count || 0;
  if (!collector._count) {
    setTimeout(function() {
      target();
      collector._count=0;
    }, 0);
  }
  collector._count++;
}