Problem returning a Proc

b.candler at pobox.com b.candler at pobox.com
Tue Sep 11 08:48:56 EDT 2007


I'm just playing with a recent Merb trunk (-r590). All the specs pass, apart 
from 2 pending. 

Now, the README says: "if you return a Proc object from your action, it will 
be called and the return value sent to the client." 

However this doesn't seem to work with the following test controller: 

class Hello < Application
 def world
   res = "Hello world from #{$$} at #{Time.now}!\n"
   proc {
     sleep 5
     res
   }
 end
end 

I get the 5 second wait, but zero bytes of response. 

$ telnet localhost 4000
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
GET /hello/world HTTP/1.0 

HTTP/1.1 200 OK
Connection: close
Date: Tue, 11 Sep 2007 12:43:51 GMT
Content-Type: text/html
Content-Length: 0 

Connection closed by foreign host. 

It works if I remove the proc { ... } wrapper and just return the string 
directly. 

I'm pretty sure I'm doing the proc return correctly; if I write it as a 
standalone Ruby program then it behaves as I expect, i.e. 

def world
 res = "Hello world from #{$$} at #{Time.now}!\n"
 proc {
   sleep 5
   res
 }
end
puts world.call   # this works and shows the message 

Anybody got any idea why this doesn't work? I'm not submitting this as a 
ticket as I'm not sure if the behaviour is wrong, the README is wrong, or 
I'm doing something wrong :-) 

Thanks, 

Brian. 


More information about the Merb-devel mailing list