posted 11 years ago
I was wondering if there is a way in JavaScript to make sure that one function doesn't run until a previous one is finished. Generally, it isn't a problem. But I do run some functions in my work that take a few seconds to complete. And by then the next function in the line has already started. Problem is the second function might be reliant on data from the first. Take this example code for example:
If you open up your console and run this, you'll notice that it prints all of the numbers from the B loop before the A loop, because the A loop has a 2 second delay on it. I need to find a way to be able to line up multiple functions, but make sure that B doesn’t run until A is done, and C doesn't run until B is done, etc. Is this possible?