title: Handling quick succession of function calls - Javascript / underscore.js / node.js
body: <p>I'm looking for a way to call a different function if it's getting called in quick succession. The first call needs to go through as quick as possible though.</p>
  
  <p>So far I've tried the <code>_.throttle</code> and <code>_.debounce</code> from <a href="http://underscorejs.org/" rel="nofollow">Underscore.js</a> to handle that and it's almost what I'm looking for but not quite. I can delay the orignal function call with these, but I want to call an entire different one when multiple calls happen at once.</p>
  
  <p>Is this possible or </p>
  
  <p>example:</p>
  
  <pre><code>var _ = require("underscore")._;
  
  function foo(){
     console.log("foo");
  }
  
  function bar(){
     console.log("bar");
  }
  
  var delayedFoo = _.throttle(foo, 1000);
  </code></pre>
  
  <p>instead throttle I want foo() to be called once and then bar() for the specified duration, before foo() can be called again:</p>
  
  <pre><code>var delayedFoo = _.route(foo, bar, 1000);
  </code></pre>
  
  <p>Is there a library or framework that has a built-in function like this?</p>