Skip to content

Instantly share code, notes, and snippets.

@bmorelli25
Last active June 10, 2021 21:01
Show Gist options
  • Save bmorelli25/6d04610644c3119a9bf6f658dbabf777 to your computer and use it in GitHub Desktop.
Save bmorelli25/6d04610644c3119a9bf6f658dbabf777 to your computer and use it in GitHub Desktop.
promise example
function doubleAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x * 2);
}, 2000);
});
}
function addPromise(x){
return new Promise(resolve => {
doubleAfter2Seconds(10).then((a) => {
doubleAfter2Seconds(20).then((b) => {
doubleAfter2Seconds(30).then((c) => {
resolve(x + a + b + c);
})
})
})
});
}
addPromise(10).then((sum) => {
console.log(sum);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment