The code in the question will definitely call those functions in that order.
However, it sounds like those functions do asynchronous work. If so, that code will start the work of all three functions (in order) and then that work will overlap, and there's no reason the work started by function2
wouldn't complete before the work started by function1
does.
In that case, you need to provide some coordination between them if you want function2
to wait to start its process until function1
is done (and so on for function2
and function3
). For instance, if they return promises, then:
function1()
.then(() => function2())
.then(() => function3())
.catch(error => {
// ...handle/report error...
});
There I've assumed all three functions want to be called with no arguments.
If they take callbacks instead, then:
function1(() => {
function2(() => {
function3();
});
});
Since callback APIs vary about how they report errors, I haven't tried to include error handling in that last example.