Created
February 23, 2017 19:42
-
-
Save afaur/811ffc853c47adc4be53b8a1277e3efb 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
var packages = [ | |
'dbcli', | |
'meow', | |
'ruff', | |
] | |
function getInfo(name, cb) { | |
if (name === 'dbcli') { | |
setTimeout(() => { | |
cb({ | |
description: 'this is a dbcli bro!', | |
}) | |
}, 5000) | |
} else { | |
setTimeout(() => { | |
cb({ | |
description: `this is a ${name} man!`, | |
}) | |
}, 5000) | |
} | |
} | |
var promise = Promise.resolve() | |
packages.forEach((package) => { | |
promise = promise.then(() => { | |
return new Promise((resolve) => { | |
getInfo(package, (info) => { | |
console.log(package, info) | |
resolve() | |
}) | |
}) | |
}) | |
}) | |
/* | |
var promises = packages.map((package) => { | |
return new Promise((resolve) => { | |
getInfo(package, (info) => { | |
resolve({ | |
name: package, | |
description: info.description, | |
}) | |
}) | |
}) | |
}) | |
Promise.all(promises).then((packages) => { | |
console.log('wat', packages) | |
}) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment