Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Created March 27, 2019 23:47
Show Gist options
  • Save ilearnjavascript/80d82902b8a0a51927330e46d46baacc to your computer and use it in GitHub Desktop.
Save ilearnjavascript/80d82902b8a0a51927330e46d46baacc to your computer and use it in GitHub Desktop.
es8 - async await - 4.js
function promise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('1. First thing setting up second thing');
resolve();
}, 1000)
})
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('2. Second thing setting up third thing');
resolve();
}, 1000)
})
})
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('3. Third thing setting up fourth thing');
resolve();
}, 1000)
})
})
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('4. Fourth thing setting up fifth thing');
resolve();
}, 1000)
})
})
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('5. Fifth thing');
resolve();
}, 1000)
})
})
.catch(error => {
console.log(`It's all a big mistake.`);
})
.finally(() => {
console.log('End');
})
}
promise();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment