title: Javascript: Trigger action on function exit
body: <p>Is there a way to listen for a javascript function to exit? A trigger that could be setup when a function has completed?</p>
  
  <p>I am attempting to use a user interface obfuscation technique (BlockUI) while an AJAX object is retrieving data from the DB, but the function doesn't necessarily execute last, even if you put it at the end of the function call. </p>
  
  <p>Example:</p>
  
  <pre><code>function doStuff() {
    blockUI();
    ajaxCall();
    unblockUI();
  };
  </code></pre>
  
  <p>Is there a way for doStuff to listen for ajaxCall to complete, before firing the unBlockUI? As it is, it processes the function linearly, calling each object in order, then a separate thread is spawned to complete each one. So, though my AJAX call might take 10-15 seconds to complete, I am only blocking the user for just a split-second, due to the linear execution of the function.</p>
  
  <p>There are less elegant ways around this...putting a loop to end only when a return value set by the AJAX function is set to true, or something of that nature. But that seems unnecessarily complicated and inefficient.</p>