I'm posting an update to the aggregator code I blogged about yesterday. This update does a few things - and demonstrates a bug (I think) in CFTHREAD inside a UDF.
First off - I took the suggestion of using an array of feeds instead of a list in case your URL contains a comma. I also let you pass in one URL by itself. The code to handle this is relatively simple. I see if arguments.feeds is not an array. If it isn't, I create a new array and set the string as the first item.
Secondly - the bug I mentioned above. If you call the UDF I wrote yesterday twice (or more), then you get an error stating that the thread named "thread_X" cannot be created twice. It was my understanding that a thread created inside a UDF was unique to the UDF. I've got a bug open with Adobe on this now. To fix this for now - I simply switched to threads named by UUID.
Lastly, I added some basic error checking to the feed retrieval. If a feed URL is bad, or times out, then I return an empty query for that particular feed.
This will be posted to CFLib later in the week when I set up "CF8" as a supported platform. You can download the zip (which has the UDF and a few test calls) here.
Archived Comments
@Ray:
I've run across information that talked about how the THREAD scope works, but I can't find any of the links. However, I believe this is the intended behavior.
Has anyone else noticed that, according to firebug, the scripting generated by CF throws 18 errors on your example page?
Good catch there Bash. It seems like CF isn't escaping quotes inside of tool tips. I'll file a bug.
Even if a thread has been rejoined, and thus should not still exist, you can't create a new thread with the same name during the same page request. I tried doing something like this:
<cfloop from="1" to="5" index="i">
<cfthread name="a"><cfset b=1></cfthread>
<cfthread action="join" name="a"/>
</cfloop>
Silly, yes, but the point is that it doesn't work. You get that same "threads must be unique" error, even though you can logically see that it should never be a problem. Why thread scope is tied to request scope, I'm unsure.
Based on my own tests and what I've been told by Adobe support people, threads are magical things with their own scope-that-shall-not-be-named.
<cfquery name="totalentries" dbtype="query">
select #collist#
from totalentries
order by publisheddate desc
</cfquery>
The publisheddate value in RSS feeds uses a string format (ie Wed, 06 June 2007 04:17:02 +1000) which means the query is sorted alphabetically by the day of the week. Ie Wed, Tue, Thu, Sun, Sat, Mon, Fri.
I'll take a look at that Ben. I seem to remember seeing something in the docs. Worst comes to worst - I'll scan and set to a 'real' date object. It will slow things down, but worth it for the proper sorting.