-
-
Save ilearnjavascript/a0af3c4d06f201207d8c7eb61b81e7e7 to your computer and use it in GitHub Desktop.
es8 - async await - 5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function func1() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log('1. First thing setting up second thing'); | |
resolve(); | |
}, 1000) | |
}) | |
} | |
async function func2() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log('2. Second thing setting up third thing'); | |
resolve(); | |
}, 1000) | |
}) | |
} | |
async function func3() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log('3. Third thing setting up fourth thing'); | |
resolve(); | |
}, 1000) | |
}) | |
} | |
async function func4() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log('4. Fourth thing setting up fifth thing'); | |
resolve(); | |
}, 1000) | |
}) | |
} | |
async function func5() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log('5. Fifth thing'); | |
resolve(); | |
}, 1000) | |
}) | |
} | |
async function loadFuncs() { | |
try { | |
await func1(); | |
await func2(); | |
await func3(); | |
await func4(); | |
await func5(); | |
} | |
catch (err) { | |
console.error(`ERROR(${err.code}): ${err.message}`); | |
} | |
finally { | |
console.log('End'); | |
} | |
} | |
loadFuncs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment