i have a function that return a success callback when it's the process succeed and a fail callback when the process failed .
the problem is how to wait the function untill it finished and get the returned value before continue to execute other code .
i tried to use the $.deffered, promise functions that provide jquery but it doesn't seems to work with non-ajax function .
this is how it looks like my function
function process(){
var picture = foo(parameters,callbackOnSuccess,callbackOnFail);
var picture1 = bar(parameters,callbackOnSuccess,callbackOnFail);
// wait untill the values are returned and do some code with picture and picture1 vars ...
}
function callbackOnSuccess(res){
return res.pictureID;
}
function callbackOnFail(error){
return error.message;
}
PS : i can't put my whole code on the CallbackOnSuccess as it's not a solution especially when i have a lot of function that i need to wait for .