Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > async http request

Reply
Thread Tools

async http request

 
 
Bob Aman
Guest
Posts: n/a
 
      03-15-2005
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


 
Reply With Quote
 
 
 
 
James Britt
Guest
Posts: n/a
 
      03-15-2005
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


 
Reply With Quote
 
 
 
 
Bob Aman
Guest
Posts: n/a
 
      03-15-2005
On Tue, 15 Mar 2005 11:45:59 -0700, Ben Schumacher
<(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
async http handler crashes occasionally on iis7 Mark Weaver ASP .Net 0 02-07-2010 03:58 PM
Newbie: async mode dedicated versus async mode interactive!! Pink_Floyd Cisco 4 06-16-2006 12:16 AM
HTTP POST in C# CodeBehind and Async Encryption jacob.eiler@gmail.com ASP .Net 0 03-27-2006 04:41 AM
Is HTTP an Async Protocol Bob Badger ASP .Net 4 02-01-2006 03:25 PM
Async webservice call in async webpage (.Net 2.0) does not return Steven ASP .Net Web Services 0 11-30-2005 01:06 AM



Advertisments