Created
November 29, 2017 03:07
-
-
Save jonathanborges/0683b49ea370dfa4a138ca263f51975a to your computer and use it in GitHub Desktop.
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 callbackFunc = (name, callback) => { | |
setTimeout(() => { | |
return callback(name + '123'); | |
}, 3000); | |
} | |
const qCallbackFunc = (name) => { | |
return new Promise((resolve, reject) => { | |
callbackFunc(name, (result) => { | |
console.log(result); | |
resolve(result); | |
}) | |
}) | |
} | |
let arr = ['Jonathan', 'Auro', 'Fernando']; | |
let i = 0; | |
let len = arr.length; | |
let promises = []; | |
for(; i<len; i++) { | |
promises.push(qCallbackFunc(arr[i])) | |
} | |
Promise.all(promises).then(() => { | |
console.log('finished all callbacks!'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment