async http request

Discussion in 'Ruby' started by Bob Aman, Mar 15, 2005.

  1. Bob Aman

    Bob Aman Guest

    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
     
    Bob Aman, Mar 15, 2005
    #1
    1. Advertising

  2. Bob Aman

    James Britt Guest

    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
     
    James Britt, Mar 15, 2005
    #2
    1. Advertising

  3. Bob Aman

    Bob Aman Guest

    Re: [Rails] async http request

    On Tue, 15 Mar 2005 11:45:59 -0700, Ben Schumacher
    <> 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
     
    Bob Aman, Mar 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Badger

    Is HTTP an Async Protocol

    Bob Badger, Jan 31, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    564
    Kevin Spencer
    Feb 1, 2006
  2. Replies:
    0
    Views:
    961
  3. Mark Weaver
    Replies:
    0
    Views:
    937
    Mark Weaver
    Feb 7, 2010
  4. Steven
    Replies:
    0
    Views:
    406
    Steven
    Nov 30, 2005
  5. Rm Rm

    http post is async or sync?

    Rm Rm, Jan 4, 2008, in forum: Ruby
    Replies:
    4
    Views:
    163
    Paul Stickney
    Jan 7, 2008
Loading...

Share This Page