0

Is there any way I can make my js function wait until the callback return value. I need this because the rest part of my js function have to use the returned value from the callback.

3
  • you may set interval and check a variable.. but that's not the good thing to do. Commented Jun 15, 2016 at 13:38
  • 1
    Can you show some code explaining what you want to do ? Commented Jun 15, 2016 at 13:39
  • Are you using an ajax call or something? Commented Jun 15, 2016 at 13:39

2 Answers 2

0

A lot of libraries or frameworks offer comfort callback value. Yoy can look for the Jquery promise, bluebird promise, angular promise.

If you do not want to use third party libs, you can implement them by yourself, using setInterval method.

Sign up to request clarification or add additional context in comments.

Comments

0

You can't make your function to wait until the callback return. What you can do is move the rest of your workflow to the success call back of the function.

I have put a sample code of Ajax call here.

    $.get( _RequestURL, function () {}).done(function (success) {
        //Put the rest of your workflow here.

    }).fail(function (err) {
        //Put the error handler methods here.

    });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.