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("<content goes here>", website.value)

Depends what you mean by "with asynchronous IO". Do you want to keep 
calling select() and then only read data when its available? Then you're 
basically rewriting eventmachine or io-reactor.

Otherwise, you can do res.read_body with a block - it will be called for 
each chunk. But read_body will still block until the body is complete.

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

But if you don't want the code to block until the body has read, but you 
don't want the read to take place in another thread, then what do you 
want?

What's the problem with threads anyway? Being able to do one thing while 
you're waiting for something else to complete is exactly what they're 
for.
-- 
Posted via http://www.ruby-forum.com/.