Skip to content

Instantly share code, notes, and snippets.

@max8hine
Created September 6, 2018 11:46
Show Gist options
  • Save max8hine/d62d6bb750e4b40988012f08c59e71b6 to your computer and use it in GitHub Desktop.
Save max8hine/d62d6bb750e4b40988012f08c59e71b6 to your computer and use it in GitHub Desktop.
nested promise with promise.all
const promise = num => new Promise((resolve) => {
setTimeout(() => { resolve(num) }, 500)
})
var arr1 = [1,2,3,4,5].map(x => promise(x))
arr1
var arr2 = [6,7,8,9,0].map(x => promise(x))
arr2
const resolvePromise = async function () {
let a = await Promise.all(arr1)
let b = await Promise.all(arr2)
a
b
const result = await Promise.all([ a, b ])
result
}
resolvePromise()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment