title: wait for async to complete before return
body: <p>mongoosejs async code . </p>
  
  <pre><code>    userSchema.static('alreadyExists',function(name){
      var isPresent;
          this.count({alias : name },function(err,count){
          isPresent = !!count
          });
      console.log('Value of flag '+isPresent);
      return isPresent;
  }); 
  </code></pre>
  
  <p>I know isPresent is returned before the this.count async function calls the callback , so its value is undefined . But how do i wait for callback to change value of isPresent and then safely return ?</p>
  
  <p>what effect does 
  <code>(function(){ asynccalls() asynccall() })();</code> has in the async flow .
  What happens if var <code>foo = asynccall() or (function(){})()</code> 
  Will the above two make return wait ? </p>
  
  <p>can <code>process.nextTick()</code> help?</p>
  
  <p>I know there are lot of questions like these , but nothing explained about problem of returning before async completion</p>