Leaky Functional Bucket

Posted on

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++;
}

Leave a Reply

Your email address will not be published. Required fields are marked *