Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

async http request

23 views
Skip to first unread message

Bob Aman

unread,
Mar 15, 2005, 1:31:44 PM3/15/05
to
I'm currently working on a ruby on rails page that needs to query a
web service, retrieve a few rss feeds and do a whole bunch of SQL
queries. Right now, my code is doing all of this somewhat
inefficiently. Ideally, I'd like to be able to do the http requests
on the page asynchronously if possible. However, I have yet to find
any example code or documentation that shows how to do this. I saw
the http-access2 library, though that seemed quite complicated
compared to the open-uri method I'm using now. Any suggestions about
how best to go about this? In the end, I really just need to have it
work, and have it be fast.
--
Bob Aman


James Britt

unread,
Mar 15, 2005, 3:20:51 PM3/15/05
to
Bob Aman wrote:
> I'm currently working on a ruby on rails page that needs to query a
> web service, retrieve a few rss feeds and do a whole bunch of SQL
> queries. Right now, my code is doing all of this somewhat
> inefficiently. Ideally, I'd like to be able to do the http requests
> on the page asynchronously if possible. However, I have yet to find
> any example code or documentation that shows how to do this. I saw
> the http-access2 library, though that seemed quite complicated
> compared to the open-uri method I'm using now. Any suggestions about
> how best to go about this?

This is on the server, correct?

Can you use Ruby threads for each of the various requests?


James Britt


http://www.ruby-doc.org
http://www.rubyxml.com
http://catapult.rubyforge.com
http://orbjson.rubyforge.com
http://www.jamesbritt.com


Bob Aman

unread,
Mar 15, 2005, 3:48:11 PM3/15/05
to
On Tue, 15 Mar 2005 11:45:59 -0700, Ben Schumacher
<bensch...@gmail.com> wrote:
> Bob-
>
> How about this?
>
> def request_urls(urls = [])
> reqs = []
> urls.each do |url|
> reqs.push Thread.new { open(url) }
> end
>
> reqs.collect { |req| req.value }
> end
>
> responses = request_urls [ 'http://www.blahr.com/', 'http://www.news.com/' ]

Just checked, and this does seem to work. Thanks!
--
Bob Aman


0 new messages