From: Daniel N Date: 2010-05-18T12:41:07+09:00 Subject: Re: Asynchronous HTTP request --000e0cd33004738e420486d61c40 Content-Type: text/plain; charset=ISO-8859-1 On 13 May 2010 17:37, Daniel DeLorme 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("", website.value) > > I'm not sure I understand EventMachine, but it doesn't seem like this code > fits with the "event loop" model. Besides, I don't want to react to every > chunk of data that comes it; I just want the result at the end. > > Thanks. > Event machine is perfect for this kind of stuff. Weather it fits with the rest of your web framework is more likely the thing that makes it an unlikely selection (if you're using anything rack based for example) http://eventmachine.rubyforge.org/EventMachine/Protocols/HttpClient.html or http://eventmachine.rubyforge.org/EventMachine/Protocols/HttpClient2.html Give an example of how this is used. HTH Daniel --000e0cd33004738e420486d61c40--