Skip to content

Instantly share code, notes, and snippets.

@ndabAP
Created October 24, 2017 14:16
Show Gist options
  • Save ndabAP/bffe03001a738d22de9b9b2a19af939c to your computer and use it in GitHub Desktop.
Save ndabAP/bffe03001a738d22de9b9b2a19af939c to your computer and use it in GitHub Desktop.
Creating async functions in JavaScript
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