129
rated 0 times
[
131]
[
2]
/ answers: 1 / hits: 23837
/ 10 Years ago, fri, october 10, 2014, 12:00:00
Here I have two JS async functions running simultaneously.
When one has ended (callback has been run), I would like to stop other one to go ahead. However (that's my issue) I cannot use global vars.
Then, I would like to know if it is possible to stop a pending function in JS or any way to solve my problem.
I will appreciate any answers :)
EDIT:
Some clarifications:
- I am here using pure JS. No HTML provided.
- When I am talking about asynchronous, it could be every async function, not only ajax (database, timeout etc.).
- We do not know their runtime.
About code, here is a sample of what I would like to produce:
asyncFirst(
// ... args
function() { // callback
console.log('foo');
stopOther();
}
);
asyncSecond(
// ... args
function() { // callback
console.log('bar');
stopOther();
}
);
asyncFirst(...);
asyncSecond(...);
What algorithm for stopOther() without using 'state' vars?
More From » asynchronous