how to wait for a function to finish in javascript
function firstFunction(_callback){
// do some asynchronous work
// and when the asynchronous stuff is complete
_callback();
}
function secondFunction(){
// call first function and pass in a callback function which
// first function runs when it has completed
firstFunction(function() {
console.log('huzzah, I\'m done!');
});
}function doFirst() {
return new Promise(function(resolve, reject) {
//do a thing
if (){
return reject(value);
}
resolve(value);
});
});
}
async function doSecond() {
var outputValue = await doFirst();
console.log(outputValue);
}
Also in JavaScript:
- javascript fetch json
- help source code discord.js
- page is loading from previous page scroll in reactjs
- jquery add style
- how to use the map method in javascript
- how to clear pod cache in react native
- installing node on ec2 instance
- $.fn.dataTable.tables in container
- how to check if 2 images are touching js
- reload page javascript
- how to write statefull class in react
- javascript select letter in string
- javascript string proper case
- merge array no duiplicates js
- javascript map value nested object
- js !==
- geolocation speed
- how could you implement javascript into java
- float to currency js
- javascript find unique values in array of objects
- js convert order to char
- react map wait axios call
- Object destructuring
- how to wait for a function to finish in javascript