Created
December 1, 2016 13:34
-
-
Save vojtatranta/40eaafd8088bf010664c9e862ef80b7b to your computer and use it in GitHub Desktop.
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
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: '[email protected]'}, {email: '[email protected]'}].map(email => { | |
return asyncFn(email.email) | |
}) | |
Promise.all(promises).then((results) => { | |
results[0] // --- {email: [email protected], status: 'ok' } | |
results[1] // --- {email: [email protected], status: 'ok' } | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment