Edit: Worth to say that is not duplicate, because in the marked duplicate; none of the functions have a child function inside. so returns from child don't return to parent.
--
I have an async function inside a IIEF. Like this
$(function($){
asyncAction((result)=>{
if(result == someValidation()){
return false;
}
})
console.log("don't execute this");
});
I need the return false to be executed for the parent IIEF function (it stops a global program flow)
However, there are 2 problems:
- Return false executes for child function, not for the parent (because it's a callback)
- Console.log executes because the asyncAction is not stopping anything.
How can I stop parent function to stop executing after the return false fron async child?
What I've tried:
$(function($){
let resultToParent = true;
asyncAction((result)=>{
if(data == someValidation()){
resultToParent = false;
}
})
if(resultToParent == false){
return false;
}
});
But this does not work because the child async.
$(function($){
try{
asyncAction((result)=>{
if(data == someValidation()){
throw Error
}
})
}
catch(err){return false}
});
But this does not work because try/catch works for synchronous only? (not sure about this?)
-- Thanks for the help!