Async
async function legen() {
return "dary";
}
is the same as
const legen = async () => {
return "dary";
}
is the same as
function legen() {
return Promise.resolve("dary");
}
Usage
cool().then(
function(value) { /* happy case code */ },
function(error) { /* some error handling */ } // is optional
);
is the same as
let wait_for_it = await legen(); //
Gotchas:
- await can only be used inside an async function => on global lvl you must go with .then()
- [].forEach() does not work on arrays returned by async functions! Need to use for ... of loop