Closed nintendoMan closed 4 years ago
A solution could be use Promise.all + map. I'm sure that you could write it cleaner...
var tall = require('tall').default
var urlArray = [
'http://loige.link/b',
'http://loige.link/gh',
'http://loige.link/codemotion-rome-2017'
];
async function tallMultiple(arrayUrl) {
try {
let unshortenedUrls = await Promise.all(urlArray.map(async (item) =>{return await tall(item)}))
console.log(unshortenedUrls);
} catch( err) {
console.error('AAAW 👻', err)
}
}
tallMultiple(urlArray)
Tall already returns a promise, so you can rewrite the above proposal by @fiblan as follows:
const tall = require('tall').default
const tallMany = (urls) => Promise.all( urls.map( url => tall(url) ) )
async function main() {
const urls = [
'http://loige.link/b',
'http://loige.link/gh',
'http://loige.link/codemotion-rome-2017'
]
const expandendUrls = await tallMany(urls)
console.log(expandendUrls) // ['https://www.nodejsdesignpatterns.com/', 'https://github.com/lmammino', 'https://slides.com/lucianomammino/universal-js-web-applications-with-react-codemotion-rome-2017']
}
main()
▶️ Run this code on runkit.com
Is this such a common use case to make sense to introduce something like tallMany
here in the library itself?
In any case, let me know if this works for you :)
Closing this one. Le t me know if you still have issues
Hi,
As investigating while trying to get this work with array of urls => does not work? If there is a away to do it, write it down?
Simple as but not able to get it work.