Skip to content

Instantly share code, notes, and snippets.

@vojtatranta
Created December 1, 2016 13:34
Show Gist options
  • Save vojtatranta/40eaafd8088bf010664c9e862ef80b7b to your computer and use it in GitHub Desktop.
Save vojtatranta/40eaafd8088bf010664c9e862ef80b7b to your computer and use it in GitHub Desktop.
const asyncFn = (email) => {
return new Promise((resolve, reject) => {
$.get('//idnes.cz/' + email, (err, result) => {
if (err) {
return resolve({
status: 'fail',
email: email,
})
}
return resolve({
status: 'ok',
email: email,
})
})
})
}
const promises = [{email: 'vojta.tranta@gmail.com'}, {email: 'duro@avocode.com'}].map(email => {
return asyncFn(email.email)
})
Promise.all(promises).then((results) => {
results[0] // --- {email: vojta.tranta@gmail.com, status: 'ok' }
results[1] // --- {email: vojta.tranta@gmail.com, status: 'ok' }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment