From: Daniel N on 18 May 2010 01:04 [Note: parts of this message were removed to make it a legal post.] 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(a)medioh.com> wrote: > On Thu, May 13, 2010 at 1:37 AM, Daniel DeLorme <dan-ml(a)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 >
From: Tony Arcieri on 18 May 2010 00:19 [Note: parts of this message were removed to make it a legal post.] On Thu, May 13, 2010 at 1:37 AM, Daniel DeLorme <dan-ml(a)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
First
|
Prev
|
Pages: 1 2 3 Prev: Rake versus Ruby? Next: Read text file and set the values in the Variables |