title: Javascript Angular resolve chain of promises before returning a result value
body: <p>I'm using a chain of promises in angular and I would like that at the end of the chain a value should be returned:</p>
  
  <pre><code>this.calculateeventsattended = function(username) {
     var Attendees = Parse.Object.extend("Attendees");
     var User = Parse.Object.extend("User");
     var count_pres = 0
     query1 = new Parse.Query(Attendees);
     query1.equalTo("user_id",username);
     query1.equalTo("presence",true)        
  
     var promise = query1.count(function(count){
         count_pres = count
     }).then(function(){
         query2 = new Parse.Query(User);
         query2.equalTo("username",username);
         query2.first().then(function(object){
             alert("parse" + count_pres)
             object.set("events_attended",count_pres)
             object.save()
         })
     })
  $q.all(promise)
  return count_pres
  }
  </code></pre>
  
  <p>the chain 'promise' is not resolved before the return is passed: count_pres is returned before the  $q.all(promise) is finished. Any idea?</p>