I need to execute the f2
function only after the completion of f1
, regardless of whether f1
is synchronous or asynchronous. To achieve this, I came up with a solution using a combination of Promise
and a timer:
executeFunctions() {
this.f1().then(result => {
this.f2()
})
}
f1() {
return new Promise<any>((resolve, reject) => {
// Code for f1...
setTimeout( () => {
resolve(x);
}, 1500); // Simulating delay
});
}
f2() {
// Code for f2...
}
However, this approach always introduces a fixed delay of 1500ms. I am looking for a way to have f2
start immediately after the completion of f1
, without any unnecessary waiting time. Is there a more precise way to synchronize the execution of these functions?