3

I'm trying to map over some RSS feeds using feedparser-promised, but my call to Promise.all() isn't returning anything. (use of var is from my REPL, which doesn't support const or let)

var feedparser = require('feedparser-promised');
var R = require('ramda');
var URLS = ['http://feeds.gawker.com/gizmodo/full',
            'http://kotaku.com/vip.xml',
           'http://www.medievalhistories.com/feed/'];

var getAllFeeds = (urls) => {
    promises = R.map(feedparser.parse, urls);
    Promise.all(promises)
        .then((itemArrs) => itemArrs)
        .catch((err) => {throw new Error(err)});
}

var x = getAllFeeds(URLS);
console.log(x);

x comes back as undefined. If I do a log on promises, it shows as an array of Promises, as expected. What am I missing?

Kevin Whitaker
  • 12,435
  • 12
  • 51
  • 89

1 Answers1

1

x is undefined because getAllFeeds is a arrow function with statement body that does not explicitly return.

You should return the Promise.all promise and consume the results in then/catch handlers:

var getAllFeeds = (urls) => {
    var promises = R.map(feedparser.parse, urls);
    return Promise.all(promises)
}

getAllFeeds(URLS)
  .then(items => {
    console.log(items);
  })
  .catch(err => {
    console.error(err);
  })
joews
  • 29,767
  • 10
  • 79
  • 91