Created
October 24, 2017 14:16
-
-
Save ndabAP/bffe03001a738d22de9b9b2a19af939c to your computer and use it in GitHub Desktop.
Creating async functions in JavaScript
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
const a = () => { | |
return new Promise(resolve => { | |
console.log('a') | |
resolve(1) | |
}) | |
} | |
const b = () => { | |
return new Promise(resolve => { | |
console.log('b') | |
setTimeout(resolve, 1000, 2) | |
}) | |
} | |
Promise.all([a(), b()]).then(results => console.log(results)) // a b [1, 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment