0

I am new to asynchronous callbacks. Following is what i am trying to achieve -

myFunc.prototype.dFunc= function (id) {
    var _instance = this;
     this.sdk.myMethord(id).then(function (sucessObj) {
        return sucessObj;
    }, function (error){
        //Error handling
    });
};

//using return value
function asynCheck(id){
    var retVal = test.dFunc(id);
    alert("dFunc val"+ retVal);
}

I know this won't work due to asynchronous call. I have tried returning a promise function from dFunc method but always retVal is undefined.

Please let me know for a correct way to achieve this, ie - wait for the asynchronous returns

Cœur
  • 37,241
  • 25
  • 195
  • 267
Being Coder
  • 127
  • 2
  • 10
  • "Please let me know for a correct way to achieve this, ie - wait for the asynchronous returns" — You can't. That is what asynchronous means. – Quentin Mar 08 '16 at 19:48
  • 1
    You're not returning a promise from `dfunc`, you're not returning anything. You'd really have to `return this.sdk.myMethord(id);`, and use `test.dFunc(id).then(function(retVal) { alert(…); })` in your `asyncCheck`. – Bergi Mar 08 '16 at 19:56

0 Answers0