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.
Asked
Active
Viewed 881 times
0
-
you may set interval and check a variable.. but that's not the good thing to do. – Akshay Khandelwal Jun 15 '16 at 13:38
-
1Can you show some code explaining what you want to do ? – Jose Hermosilla Rodrigo Jun 15 '16 at 13:39
-
Are you using an ajax call or something? – Nitheesh Jun 15 '16 at 13:39
2 Answers
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.

Drag13
- 5,859
- 1
- 18
- 42
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.
});

Nitheesh
- 19,238
- 3
- 22
- 49