From: Brian Candler Date: 2010-05-19T01:00:57+09:00 Subject: Re: Asynchronous HTTP request Daniel DeLorme wrote: > Brian Candler wrote: >> So you didn't want a Thread, but you'll happily use a Fiber... > > Well, yes, a Fiber is just a coroutine, nothing like a thread. Except that the semantics of Threads are well defined. You start them, they do stuff, you join them. Are you saying that a Fiber will return control to you when it blocks due to lack of data on a socket, as well as when the Fiber explicitly "yields"? What value does it return to you in the blocking case? Testing suggests otherwise. $ cat ert.rb p1, p2 = IO.pipe f = Fiber.new do puts "Starting fiber" p1.gets puts "Ending fiber" end sleep 0.5 puts "Point A" f.resume puts "Point B" $ ruby19 ert.rb Point A Starting fiber As far as I can see: the fiber starts processing when f.resume is called, but blocks when p1.gets is called. So AFAICS, your code which thinks it can do work while the the HTTP request is running, doesn't. Rather, the HTTP request is not sent at all until the Fiber#resume is called, and at that point it will block as necessary until the whole response is received. -- Posted via http://www.ruby-forum.com/.