I am trying to map an async function over an array, I hope to achieve such effect:
const result = orgs.map(org =>
f(org)
.then(res => return res))
// now result should be an array of res
console.log(result)
This would not work, so I tried another way:
const result = []
orgs.map(org =>
f(org)
.then(res => result.push(res)))
// now result should be an array of res
console.log(result)
Still, this won't work.
But I can print out the result by doing:
orgs.map(org =>
f(org)
.then(res => console.log(res)))
Any ideas on how this behavior happens?
Also I am using find-rss package over an array of links
res => return res--- And no, it still is a promise. That function does nothing. You need to read some of those numerous blog posts about promises. -- "Still, this won't work." -- Of course it doesn't, you collect promises. Just read up on what promises are and how they work. Reading documentation (includes blog posts) goes a long way towards solving soooo many problems. This is not a question worth sharing and archiving on SO.