I would like to use the Google AJAX Feed API to fetch multiple newsfeeds and display them on a webpage.
I can’t use Google’s FeedControl class because I want to control the way the items of the feed are displayed. That leaves me with Google’s Feed class as the only option.
I’ve got it to work with a single feed: provide a url and a callback function; process the results of the feed inside the callback function.
My question: How do i fetch multiple feeds? I would somehow have to make a new google.feeds.feed object inside the callback function and provide it with a new url and … the same callback-function (?)
I never studied computer sciences, so this kind of recursion makes my head spin.
Anyone can explain what I have to do?
Sure, you can do it that way, here’s some pseudocode:
I don’t know the Google Feed API, hence the placeholder
start_feed_downloadfunction.What that does is start the process of grabbing the feeds via the
grabFeedsfunction, which accepts an array of feeds.grabFeedskicks offfeedWorker, which initiates the first feed request, and then returns immediately (almost certainly before the first feed is retrieved).callbackprocesses the result, then asksfeedWorkerto kick off the next feed request (if there is one).The “magic” here is that
feedWorkerandcallbackare both closures, so even thoughgrabFeedshas already returned, theindexandfeedsvariables live on (in an object called an “execution context”) for as long as anything references the things inside the execution context — in our case, untilcallbackandfeedWorkerare no longer referenced by Google’s stuff.