Skip to content

Instantly share code, notes, and snippets.

@jonathanborges
Created November 29, 2017 03:07
Show Gist options
  • Save jonathanborges/0683b49ea370dfa4a138ca263f51975a to your computer and use it in GitHub Desktop.
Save jonathanborges/0683b49ea370dfa4a138ca263f51975a to your computer and use it in GitHub Desktop.
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