1

I have a function func which resolves a promise and then tries to return the updated value of a local variable returnval

func: function(){
   returnval = false;
   var promise = new Ember.RSVP.Promise(function(resolve) {
       // some stuff .. 
       returnval = true;
       resolve();
   });
   promise.then(function(){
       return returnval;
   });
}

I guess the return returnval returns from the promise object. How do I return the updated value of returnval from the func ?

mido
  • 24,198
  • 15
  • 92
  • 117
Ninja420
  • 3,542
  • 3
  • 22
  • 34

1 Answers1

-1

To have the function return:

func: function(){
   returnval = false;
   var promise = new Ember.RSVP.Promise(function(resolve) {
       // some stuff .. 
       returnval = true;
       resolve();
   });
   promise.then(function(){
       return returnval;
   });
   return returnval; //this will return from the function call
}
Scott
  • 1,863
  • 2
  • 24
  • 43