Async and Await
ES6, builds off of promises and very similar to python's asyncio
async function catFetch(userId) {
const response = await fetch('....')
return await response.json();
}Async functions return a promise and let you use await whihc waits on promises
If the awaiting(only one await at a time) is limiting you can always fall back on promises
Wait with
function delay(timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
async function ... {
....
await delay(3000);
}Async Ft == Promise
Can just use async functions in a promise
Look at babel runtime to get in the browser
Last updated