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. Advertisements

  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. Advertisements

  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. Advertisements

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. Brian Birtle
    Replies:
    2
    Views:
    2,599
    John Saunders
    Oct 16, 2003
  2. Bob Badger

    Is HTTP an Async Protocol

    Bob Badger, Jan 31, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    695
    Kevin Spencer
    Feb 1, 2006
  3. Replies:
    6
    Views:
    7,692
    Tor Iver Wilhelmsen
    Aug 29, 2005
  4. James
    Replies:
    3
    Views:
    17,425
    Roedy Green
    Nov 25, 2005
  5. nRk
    Replies:
    1
    Views:
    1,176
    Steven D'Aprano
    Feb 12, 2009
  6. Nacho Nachev
    Replies:
    2
    Views:
    1,181
  7. Steven
    Replies:
    0
    Views:
    523
    Steven
    Nov 30, 2005
  8. Gelonida N
    Replies:
    0
    Views:
    662
    Gelonida N
    Feb 27, 2012
Loading...