Wait for a function to finish before continuing in JavaScript - OpenJavaScript.info
Tue Jul 26 2022 22:08:38 GMT+0000 (Coordinated Universal Time)
Saved by
@gsinghg19
#javascript
async function task1() {
const res = await fetch('https://httpbin.org/get')
.then(res => res.json())
.then(data => console.log(data))
return res;
}
async function task2() {
// Do something with Fetch result
console.log("Done handling the Fetch result!");
}
async function executeTasks() {
await task1();
await task2();
console.log("Task 3");
}
executeTasks();
content_copyCOPY
Basic structure for async/await
https://openjavascript.info/2022/05/27/wait-for-a-function-to-finish-before-continuing-in-javascript/
Comments