I'm trying to run 2 functions synchronously. The 1st function will execute a lot slower than the 2nd function. I need it to run synchronously from 1st to 2nd.
//1st function
function first(){
$.getJSON("/update/", () => {
//updates
})
}
//2nd function
function second(){
//triggers some event
}
At this point, I've tried using Promise but to no avail, it was a fail
//Promise
var promiseVar = new Promise((resolve, reject) =>{
first(); //run the first function
//note: first() will take more time to run because it's
//grabbing something from the server to update to client
resolve('Success');
})
promiseVar.then((msg)=>{
console.log(msg);
second();
})
By using Promise, it still executes the second function while loading the first. How can I make this run sequentially?