I have a helper function that calls other functions. I want the called functions to finish before continuing on in the helper function.
currently they are both changing things at the same time.
helperDikjstras = async() => {
//do stuff
await this.colorVisited(visitedNodes); // I want this function to finish before continuing
await this.colorPath(path);
//EDIT: I've also tried:
this.colorVisited(visitedNodes).then(() => this.colorPath(path));
return;
}
colorVisited = async (visitedNodes) => {
//do stuff
return;
}
colorPath = async (path) => {
//do stuff
return;
}
Of course they do, that's the way it works. There is no "interupt" or pause capability in JavaScript. To achieve your goal, call your follow-on functions in the subsequent .then() of the first await.
Like so:
helperDikjstras = async() => {/*...*/}
colorVisited = async(visitedNodes, _callback) => {/*...*/}
colorPath = async(path) => {/*...*/}
helperDikjstras()
.then(() => colorVisited(blah, halb))
.then(() => colorPath(somePath));
If you needed to have other functions run after colorPath() you can simply add more...
helperDikjstras()
.then(() => colorVisited(blah, halb))
.then(() => colorPath(somePath))
.then(() => doSomethingElse())
.then(() => andAnother())
.then(() => etc());