There's a library I wrote specifically for external http requests in mind.
 It uses threads and blocks on first access (no callbacks).

http://github.com/hassox/muscle

  m = Muscle.new do |m|
    m.action(:users) do
      # get users from an external service
    end

    m.action(:slow_stuff, :timeout => 1.2) do
      # some unreliable action.
    end

    # Setup a special timeout handler for the second action
    # by default timeouts are set to 5 seconds
    m.on_timeout(:another) do
      "Sorry but :action timed out"
    end
  end

m[:users] # blocks when accessed until m[:users] action is completed.
Continues the remaining actions in the background


Not sure if it helps your situation, but it's simple and works effectively.


On 18 May 2010 14:19, Tony Arcieri <tony.arcieri / medioh.com> wrote:

> On Thu, May 13, 2010 at 1:37 AM, Daniel DeLorme <dan-ml / dan42.com> wrote:
>
> > Does anyone know how to do the following, but without threads, purely
> with
> > asynchronous IO?
> >
> > website = Thread.new{ Net::HTTP.get(URI.parse(url)) }
> > template = compute_lots_of_stuff()
> > puts template.sub("<content goes here>", website.value)
> >
>
> Looks like you want futures, which can be provided by any number of
> frameworks.  A pretty awesome one to consider is dataflow, which is based
> off ideas from the Oz language:
>
> http://github.com/larrytheliquid/dataflow
>
> MenTaLguY's Omnibus library also provides futures, however I don't believe
> it's presently maintained:
>
> http://rubyforge.org/projects/concurrent
>
> --
> Tony Arcieri
> Medioh! A Kudelski Brand
>