-
-
Save tomschall/af0f99fb3f84bd31aa4f0f68d5e80ca3 to your computer and use it in GitHub Desktop.
promise example
This file contains hidden or 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
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