Async and Promises - adriana-401-advanced-javascript/seattle-javascript-401n13 GitHub Wiki
JavaScript runs with a stack, async is used for processes that are put in a callback queue.
Promises is built in to JS as a constructor. To call it you can do the following code.
function resolveAfterSomeTime() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
var result = await resolveAfterSomeTime();
console.log(result);
// expected output: 'resolved'
}
asyncCall();
(pulled from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
The promise either is fulfilled, rejected, or pending.