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.
-
you may set interval and check a variable.. but that's not the good thing to do.Akshay Khandelwal– Akshay Khandelwal2016-06-15 13:38:12 +00:00Commented Jun 15, 2016 at 13:38
-
1Can you show some code explaining what you want to do ?Jose Hermosilla Rodrigo– Jose Hermosilla Rodrigo2016-06-15 13:39:11 +00:00Commented Jun 15, 2016 at 13:39
-
Are you using an ajax call or something?Nitheesh– Nitheesh2016-06-15 13:39:40 +00:00Commented Jun 15, 2016 at 13:39
Add a comment
|
2 Answers
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.
Comments
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.
});