wait for callback function to finish javascript code example
Example 1: wait until a function finishes javascript
function firstFunction(_callback){
_callback();
}
function secondFunction(){
firstFunction(function() {
console.log('huzzah, I\'m done!');
});
}
Example 2: javascript execute function after async
function a() {
return new Promise(function(resolve) {
setTimeout(function() {
console.log('a');
resolve();
}, 500)
});
}
function b() {
return new Promise(function(resolve) {
setTimeout(function() {
console.log('b');
resolve();
}, 250);
});
}
a().then(b).then(function() {})